ID:               33998
 Updated by:       [EMAIL PROTECTED]
 Reported By:      dan at stratitec dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Class/Object related
 Operating System: Linux (Red Hat 9)
 PHP Version:      5.0.3
 New Comment:

>If this is to keep recursion from happening
Yes.

>A programmer can ALWAYS shoot himself
But not THAT easy.
You can encounter infinite recursion every time you try to read
non-existent object property in __get(). 

This is by design and won't be changed.


Previous Comments:
------------------------------------------------------------------------

[2005-08-04 22:22:07] dan at stratitec dot com

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 this bug report at http://bugs.php.net/?id=33998&edit=1

Reply via email to