From:             remy dot damour at laposte dot net
Operating system: debian
PHP version:      5.2.8
PHP Bug Type:     Class/Object related
Bug description:  magic method __set() is bypassed on recursive call

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 bug report at http://bugs.php.net/?id=47215&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=47215&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=47215&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=47215&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=47215&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=47215&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=47215&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=47215&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=47215&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=47215&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=47215&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=47215&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=47215&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=47215&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=47215&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=47215&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=47215&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=47215&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=47215&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=47215&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=47215&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=47215&r=mysqlcfg

Reply via email to