From: Operating system: Debian PHP version: 5.2.14RC1 Package: *General Issues Bug Type: Bug Bug description:Unwanted call of the magic __call method
Description: ------------ hello everyone ; In the documentation, it's said that the magic __call method is called when an inaccessible member is read. But I've small issue in my current class with a setter method. When I try to set an Alias on an inexistent member, the magic __call method is also called. To solve the problem, I uses a workaround like this in the setter method: public static function &setAlias($index, &$value) { $instance = self::getInstance(); // Small workaround to avoid call of magic __get(). $instance->$index = ''; return $instance->$index = &$value; } Strange behavior, no ? It's bug or not, if not, can you explain to me the reason of this statement ? I uses php 5.2.6. Sorry, for my poor english, I'm french. Test script: --------------- class Registry { protected static $_instance = null; public static function getInstance() { if(self::$_instance == null) { self::$_instance = new self; } return self::$_instance; } public function __get($index) { print 'Oh my god...'; } public static function &setAlias($index, &$value) { $instance = self::getInstance(); return $instance->$index = &$value; } } class myObject { protected static $_instance = null; public static function &getInstance() { if(self::$_instance == null) { self::$_instance = new self(); } return self::$_instance; } } // Here, I want register a `myObject` instance by reference (not by object identifier) Registry::setAlias('MyData', myObject::getInstance()); echo '<pre>'; var_dump(Registry::getInstance()); echo '</pre>'; Expected result: ---------------- object(Registry)#2 (1) { ["MyData"]=> &object(myObject)#1 (0) { } } Actual result: -------------- Oh my god... Notice: Indirect modification of overloaded property Registry::$MyData has no effect in /var/www/test.php on line 67 Fatal error: Cannot assign by reference to overloaded object in /var/www/test.php on line 67 -- Edit bug report at http://bugs.php.net/bug.php?id=52157&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=52157&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=52157&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=52157&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=52157&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=52157&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=52157&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=52157&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=52157&r=needscript Try newer version: http://bugs.php.net/fix.php?id=52157&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=52157&r=support Expected behavior: http://bugs.php.net/fix.php?id=52157&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=52157&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=52157&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=52157&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=52157&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=52157&r=dst IIS Stability: http://bugs.php.net/fix.php?id=52157&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=52157&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=52157&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=52157&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=52157&r=mysqlcfg