#31762 [NEW]: array_shift() modifies array passed by value from class method

From: Date: Sun, 30 Jan 2005 04:38:15 +0000
Subject: #31762 [NEW]: array_shift() modifies array passed by value from class method
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-73061@lists.php.net to get a copy of this message
From: e at narod dot ru Operating system: Windows XP PHP version: 5.0.3 PHP Bug Type: Scripting Engine problem Bug description: array_shift() modifies array passed by value from class method Description: ------------ Function array_shift() modifies array passed by value from class method. In the example below $_cache is modified through array_shift() call though $_cache is always passed by value. The bug doesn't appear if we don't use classes. Reproduce code: --------------- class A { var $_cache = false; function get_array() { if (!$this->_cache) $this->_cache = array(1, 2, 3, 4, 5); return $this->_cache; } function get_shifted_array() { return array_shift($this->get_array()); } } $a = new A; for ($i = 0; $i < 5; $i++) echo $a->get_shifted_array() . "\n"; Expected result: ---------------- 1 1 1 1 1 Actual result: -------------- 1 2 3 4 5 -- Edit bug report at http://bugs.php.net/?id=31762&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31762&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31762&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31762&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=31762&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=31762&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=31762&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=31762&r=needscript Try newer version: http://bugs.php.net/fix.php?id=31762&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=31762&r=support Expected behavior: http://bugs.php.net/fix.php?id=31762&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=31762&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=31762&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=31762&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31762&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=31762&r=dst IIS Stability: http://bugs.php.net/fix.php?id=31762&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=31762&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=31762&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=31762&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=31762&r=mysqlcfg

« previous php.bugs (#73061) next »