#31762 [Opn->Bgs]: array_shift() modifies array passed by value from class method
| From: | tony2001@php.net | Date: | Thu, 03 Feb 2005 20:52:16 +0000 |
| Subject: | #31762 [Opn->Bgs]: array_shift() modifies array passed by value from class method | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-73415@lists.php.net to get a copy of this message | ||
ID: 31762
Updated by: tony2001@php.net
Reported By: e at narod dot ru
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Windows XP
PHP Version: 5.0.3
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
That's how it works.
See http://php.net/array_shift
Previous Comments:
------------------------------------------------------------------------
[2005-01-30 05:38:14] e at narod dot ru
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 this bug report at http://bugs.php.net/?id=31762&edit=1