note 71194 deleted from language.oop5.basic by colder
| From: | colder@php.net | Date: | Sun, 19 Aug 2007 23:44:12 +0000 |
| Subject: | note 71194 deleted from language.oop5.basic by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-129618@lists.php.net to get a copy of this message | ||
Note Submitter: thisbizness at gmail dot com
----
The best alternatives I think one has right now to nest a class are:
1- create the nested class in an external file and 'include' that file inside a nesting
class function. I prefer to use a static function for this.
2- put the nested class definition in a string inside a nesting class function and use the
'eval' keyword to define the class.
<?php
class MyParent{
public function parentFunction( ){
}
public static function nestedClasses(){
eval('
class MyChild{
function __construct(){
echo "this is a nested class";
}
public function childFunction( )
{
}
}
');
}
}
MyParent::nestedClasses();
$y = new MyChild();
?>