#42409 [NEW]: -> operator permanently damaged after assigning value to overloaded variable

From: Date: Fri, 24 Aug 2007 06:55:54 +0000
Subject: #42409 [NEW]: -> operator permanently damaged after assigning value to overloaded variable
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-116591@lists.php.net to get a copy of this message
From: luke dot mcildoon at niche dot com dot au Operating system: Windows Vista 32-bit PHP version: 5.2.3 PHP Bug Type: Scripting Engine problem Bug description: -> operator permanently damaged after assigning value to overloaded variable Description: ------------ I have a class that returns an array by reference using __get(). As soon as you try to set a 2+ dimension on the array, the -> operator returns whatever you tried to assign to the referenced array. ie. session()->session['foo'][] = 'test'; print_r($this->var); #[0] => 'test' print_r($asdf->ghjk); #[0] => 'test' Basically, from any point after the first example line is used, any use of the -> operator, regardless of the object being referenced, will return whatever you tried to assign to the referenced array. Reproduce code: --------------- class session extends ArrayObject { public $data = array(); public function &__get($var) { if($var == 'session') { return $this; } } } session()->session[][] = 'test'; print_r($this->var); print_r($anything->var); print_r($this->foobar); Expected result: ---------------- The actual value of $this->var, then undefined property warnings. Actual result: -------------- [0] => 'test' [0] => 'test' [0] => 'test' -- Edit bug report at http://bugs.php.net/?id=42409&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=42409&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=42409&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=42409&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=42409&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=42409&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=42409&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=42409&r=needscript Try newer version: http://bugs.php.net/fix.php?id=42409&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=42409&r=support Expected behavior: http://bugs.php.net/fix.php?id=42409&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=42409&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=42409&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=42409&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=42409&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=42409&r=dst IIS Stability: http://bugs.php.net/fix.php?id=42409&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=42409&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=42409&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=42409&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=42409&r=mysqlcfg

« previous php.bugs (#116591) next »