|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-08-04 22:27 UTC] tony2001@php.net
[2015-12-16 23:07 UTC] a dot teal at warwick dot ac dot uk
[2015-12-16 23:20 UTC] requinix@php.net
[2015-12-17 00:00 UTC] a dot teal at warwick dot ac dot uk
[2015-12-17 00:17 UTC] requinix@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 21 20:00:01 2025 UTC |
Description: ------------ Calling a variable using the __get() code from within a function that has been called, or is inside the __get() function itself results in the variable or result not being found. If this is to keep recursion from happening, I feel it's a poor choice. A programmer can ALWAYS shoot himself in the foot with infinite recursion, but placing limits like this is counterintuitive and prevents solutions. Also, since replacing $this->a with $this->__get('a') in the example allows the script to run as intended, a user could still use the __get function to recurse infinitely if their __get() was written improperly. Reproduce code: --------------- class test { protected $_a = 6; function __get($key) { if($key == 'stuff') { return $this->stuff(); } else if($key == 'a') { return $this->_a; } } function stuff() { return array('random' => 'key', 'using_getter' => 10 * $this->a); } } $test = new test(); print 'this should be 60: '.$test->stuff['using_getter'].'<br/>'; print 'this should be 6: '.$test->a.'<br/>'; Expected result: ---------------- this should be 60: 60 this should be 6: 6 Actual result: -------------- this should be 60: 0 this should be 6: 6 Also, note, this warning is raised: [[ Undefined property: test::$a ]] on /var/www/html/test.php