From: peter at ibuildings dot nl Operating system: Windows XP Professional PHP version: 5.2.2 PHP Bug Type: Class/Object related Bug description: Magic methods __set/__get broken
Description: ------------ I've created a small class that implements the magic __set, __get and __isset methods. Using PHP 5.1.6 I can assign an array to a "fake" instance variable and then add elements to it. Doing the same using PHP 5.2.1 or 5.2.2 doesn't change the contents of the array. I've tried returning a reference from the __get method (e.g. changes the function definition to "function &__get($key, $value) ...", but this doesn't work either (although PHP doesn't complain about it). If this wasn't supposed to work with PHP 5.1.6 how should I then implement this to get the desired behaviour? If this isn't possible at all then that means __set/__get are far less usable then before. Reproduce code: --------------- class Data { private $m_data = array(); function __set($key, $value) { $this->m_data[$key] = $value; } function __get($key) { return $this->m_data[$key]; } function __isset($key) { return isset($this->m_data[$key]); } function dump() { var_dump($this->m_data); } } $obj = new Data(); $obj->a = "a"; $obj->b = array(); $obj->b[] = '1'; $obj->b[] = '2'; $obj->b[] = '3'; $obj->dump(); Expected result: ---------------- array(2) { ["a"]=> string(1) "a" ["b"]=> array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" } } Actual result: -------------- array(2) { ["a"]=> string(1) "a" ["b"]=> array(0) { } } -- Edit bug report at http://bugs.php.net/?id=41387&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41387&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41387&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41387&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41387&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41387&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41387&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41387&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41387&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41387&r=support Expected behavior: http://bugs.php.net/fix.php?id=41387&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41387&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41387&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41387&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41387&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41387&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41387&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41387&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41387&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41387&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41387&r=mysqlcfg