From: dan at stratitec dot com
Operating system: Linux (Red Hat 9)
PHP version: 5.0.3
PHP Bug Type: Class/Object related
Bug description: Calling a getter within a getter does not work.
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
--
Edit bug report at http://bugs.php.net/?id=33998&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33998&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=33998&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=33998&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=33998&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=33998&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=33998&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=33998&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=33998&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=33998&r=support
Expected behavior: http://bugs.php.net/fix.php?id=33998&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=33998&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=33998&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=33998&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33998&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=33998&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=33998&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=33998&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=33998&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=33998&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=33998&r=mysqlcfg