我有一个类TestController ...“TestController”类扩展了一个“AppBaseController”类,它是o MVC框架的一部分...
在“TestController” __construct() 的某个时刻,我需要动态创建一个抽象类并向该类添加一些属性,假设新类名为“newClass”......稍后我需要包含一个“BasiClass” " 扩展了这个 "newClass" ...
我希望你明白我的意思...
这是代码:
TestController 类如下所示:
<?php
// TestController.php
Class TestController extend AppBaseController
{
public $property_1; // String
public $property_2; // Array
// ...
public $property_3; // Object
/*
There are also some properties declared in
AppBaseController that must be available in the
NewClass ...
Let's say that one of them is named $property_4
*/
public function __construct()
{
parent::__construct();
// ... some code ...
/*
Dynamically create a Abstract class newClass HERE and
add the the properties.
*/
// ... more code ...
}
public function Test()
{
include "BasiClass.php";
$object = new BasicClass;
echo $object->property_1;
echo $object->property_2;
echo $object->property_3;
echo $object->property_4;
}
} // End TestController
?>
BasiClass 类如下所示:
<?php
// BasiClass.php
Class BasiClass extend newClass
{
# This class extend dynamically created class newClass !!!
public function __construct()
{
// ...
}
} // End BasiClass
?>
这个想法是 BasiClass 具有公共成员 property_1、property_2、property_3 和 property_4,因为它扩展了 newClass 而 newClass 应该是动态创建的。
提前致谢!