ID:               47215
 User updated by:  remy dot damour at laposte dot net
 Reported By:      remy dot damour at laposte dot net
 Status:           Open
 Bug Type:         Class/Object related
 Operating System: debian
 PHP Version:      5.2.8
 New Comment:

Maybe this is not a bug, but simply expected behavior?
Because otherwise we could not be able to define object properties
using __set() magic method

Regards,
Remy


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

[2009-01-25 22:23:41] remy dot damour at laposte dot net

Description:
------------
Magic method __set() is bypassed on recursive call. 
PHP automatically creates a property on instance instead of recursively
calling __set() or instead of throwing a recursivity error

For additional details, please read: http://www.qc4blog.com/?p=458

Reproduce code:
---------------
class Fruits
{
        protected $_props = array(); // inner array mapping properties to
values
        
        public function __set($name, $value) 
        {
                $this->_props[$name] = $value;
                if ('apple' == $name) {
                        $this->apple = 'green';
                }
        }
}

$a = new Fruits();
$a->banana = 'yellow';
var_dump(property_exists($a, 'banana')); // output: false
$a->apple = 'red';
var_dump(property_exists($a, 'apple')); // output: true


Expected result:
----------------
Throw a recursivity exception

Actual result:
--------------
no exception thrown, property is automatically created by passing
__set()


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=47215&edit=1

Reply via email to