如何使用其他类的__construct方法中的自定义成员动态创建抽象类?

时间:2013-06-06 17:02:44

标签: php

我有一个TestController类...... “TestController”类扩展了一个“AppBaseController”类,它是o MVC框架的一部分...

在某些时候,在“TestController”__construct()中我需要动态创建一个抽象类并向该类添加一些属性,假设新类名为“newClass”... 后来我需要包含一个扩展这个“newClass”的“BasiClass”......

我希望你明白我的意思......

以下是代码:

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应该是动态创建的。

提前致谢!

0 个答案:

没有答案