Overloaded property access

php.internals

Rick Fletcher

22 years ago
I've just made use of overloaded property access for the first time and experienced some unexpected behavior. I just wanted to verify that it was the correct behavior with those who'd know best. <?php class One { public function __construct() { $this->two = new Two(); } public function __set( $n, $v ) { $GLOBALS[$n] = $v; } public function __get( $n ) { return $GLOBALS[$n]; } } class Two { public $property = "default value"; } $one = new One(); print( "\"" . $one->two->property . "\"n" ); $one->two->property = "new value"; ?> This produces: ================= $ php -f test.php "default value" PHP Fatal error: Cannot access undefined property for object with overloaded property access in /home/fletch/test.php on line 24 ================= Is it correct that $one->two->property should be read only? Thanks. Rick Fletcher

Rick Fletcher

22 years ago
After sending this mail I went and searched the bugs database more thoroughly and found this very problem here: http://bugs.php.net/bug.php?id=28444. My apologies. Rick