Does anybody know if it is possible to create new variables/functions on the fly in a parent class and have it pass down to all created children? From my experience only the last created child will receive the change.
Take a look at this code to see what I mean:
<?PHP
class Dad {
private static $instance;
function __construct() {
self::$instance =& $this;
}
public static function &get_instance()
{
return self::$instance;
}
function foo() {
echo "foo<br />";
}
}
function &get_instance() {
return Dad::get_instance();
}
class Child1 extends Dad {
function bar1() {
echo "Bar1<br />";
}
}
class Child2 extends Dad {
function bar2() {
echo "Bar2<br />";
}
}
$Kid =& new Child1();
$Kid->foo();
$Kid->bar1();
$Kid2 =& new Child2();
$Kid2->foo();
$Kid2->bar2();
echo "<hr>";
$base =& get_instance();
$base->newVar = "Bar";
var_dump($Kid);
var_dump($Kid2);
?>
When I add newVar to the parent class using an instance, it is only passed to $Kid2.
How can I make it so that both $Kid and $Kid2 get the new variable?