#20993 [Opn->Ver]: Element value changes without asking
| From: | msopacua@php.net | Date: | Fri, 13 Dec 2002 18:42:23 +0000 |
| Subject: | #20993 [Opn->Ver]: Element value changes without asking | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-27640@lists.php.net to get a copy of this message | ||
ID: 20993
Updated by: msopacua@php.net
Reported By: henrik.gebauer@web.de
-Status: Open
+Status: Verified
Bug Type: Variables related
-Operating System: Windows 2002
+Operating System: Any
-PHP Version: 4.3.0RC3
+PHP Version: 4.0CVS-2002-12-13
New Comment:
Verified and added testcase to CVS
Previous Comments:
------------------------------------------------------------------------
[2002-12-13 12:01:33] henrik.gebauer@web.de
I create an array an then a reference to an element of that array.
Then the array is passed to a function (by value!) which changes the
value of the element.
After that, the global array has also another value.
I would expect this behaviour if I passed the array by reference but I
do not.
<?php
$array = array(1);
$reference =& $array[0];
echo $array[0], '<br>';
theFunction($array);
echo $array[0], '<br>';
function theFunction($array) {
$array[0] = 2;
}
?>
------------------------------------------------------------------------
[2002-12-13 12:00:37] henrik.gebauer@web.de
I create an array an then a reference to an element of that array.
Then the array is passed to a function (by value!) which changes the
value of the element.
After that, the global array has also another value.
I would expect this behaviour if I passed the array by reference but I
did not.
<?php
$array = array(1);
$reference =& $array[0];
echo $array[0], '<br>';
theFunction($array);
echo $array[0], '<br>';
function theFunction($array) {
$array[0] = 2;
}
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=20993&edit=1