|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-07-17 22:12 UTC] johannes@php.net
[2007-07-17 22:36 UTC] johannes@php.net
[2007-07-18 15:33 UTC] o_gangrel at hotmail dot com
[2007-07-31 21:21 UTC] o_gangrel at hotmail dot com
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 14:00:02 2025 UTC |
Description: ------------ In a class, if instance this same class inside, the method __get() does not is called. Reproduce code: --------------- class class_test { private $sub_classes = array(); private $foo = "bar"; // Default value public function __construct($n = 0) { for($i = 0; $i < $n; $i++) { $this->sub_classes[] = new class_test(); // New "sub" instaces } if($n > 0) { $this->foo = $n; // Change the default value on main instace } } public function __get($name) { switch($name) { case 'foo': return '__get("foo") = '.$this->foo; // Getting the variable, changing the value break; case 'subs': $subs = '$this->foo = '.$this->foo."\n"; // Value of var on main instace foreach($this->sub_classes as $key => $sub_class) { $subs.= "\$this->sub_classes[$key]->foo = ".$this->sub_classes[$key]->foo."\n"; // The value of variable on each "sub" instace } return $subs; break; } return false; } } $test = new class_test(2); // Create the main instace, with 2 "sub" instaces echo $test->subs; // Show the variables Expected result: ---------------- $this->foo = 2 $this->sub_classes[0]->foo = __get("foo") = bar $this->sub_classes[1]->foo = __get("foo") = bar Actual result: -------------- $this->foo = 2 $this->sub_classes[0]->foo = bar $this->sub_classes[1]->foo = bar