Object Overloading in PHP5

From: Date: Sat, 28 Aug 2004 13:19:39 +0000
Subject: Object Overloading in PHP5
Groups: php.general 
Request: Send a blank email to php-general+get-195002@lists.php.net to get a copy of this message
Do you guys have any idea why this code: <?php class Foo { private $elem = array(); public function __get ($prop) { if (isset($this->elem[$prop])) { return $this->elem[$prop]; } else { trigger_error("Property '$prop' not defined", E_USER_ERROR); } } public function __set ($prop, $val) { $this->elem[$prop] = $val; } } $obj = new Foo; $obj->a = new Foo; $obj->a->b = "Foobar"; ?> returns this: Fatal error: Cannot access undefined property for object with overloaded property access in ... on line 24 Where line 24 is: $obj->a->b = "Foobar"; ? -- Daniel Schierbeck

« previous php.general (#195002) next »