note 101751 deleted from keyword.extends by danbrown

From: Date: Sun, 09 Jan 2011 17:39:16 +0000
Subject: note 101751 deleted from keyword.extends by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175583@lists.php.net to get a copy of this message
Note Submitter: agita at live dot de ---- // I've modified the snippet from f4bi0_ to fit my own needs // Now you can do something like "$Ext2 = new $AL->Ext2;" // (It's not fully tested out yet...) <?php if (!class_exists("AgiLab")) { class AgiLab { private $childs = array(); public function add($child) { if (gettype($child) == "object") $this->childs[get_class($child)] = $child; else if (gettype($child) == "string") $this->childs[$child] = $child; } public function __get($varname) { if (isset($this->childs[$varname])) return $this->childs[$varname]; foreach ($this->childs as $child) if (gettype($child) == "object") if (property_exists($child, $varname)) return $child->$varname; } public function __call($method, $args) { foreach ($this->childs as $child) if (gettype($child) == "object") if (method_exists($child, $method)) return call_user_method_array($method, $child, $args); } } $AL = new AgiLab(); } /********************/ class Ext1{ private $name=""; private $id=""; public function setID($id){$this->id = $id;} public function setName($name){$this->name = $name;} public function getID(){return $this->id;} public function getName(){return $this->name;} } $AL->add(new Ext1()); /********************/ class Ext2{ private $address=""; private $country=""; public function setAddress($address){$this->address = $address;} public function setCountry($country){$this->country = $country;} public function getAddress(){return $this->address;} public function getCountry(){return $this->country;} } $AL->add(Ext2); /********************/ $AL->setName("Agita"); echo $AL->getName()."<br>"; $AL->setCountry("Germany"); echo $AL->getCountry()."<br>"; // doesnt work $Ext2 = new $AL->Ext2; $Ext2->setAddress("Hannover"); echo $Ext2->getAddress()."<br>";

« previous php.notes (#175583) next »