ID: 37917
Updated by: [EMAIL PROTECTED]
Reported By: andrea dot busia at axis-sv dot it
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Linux / WinXp
PHP Version: 5.1.4
New Comment:
$a[1] =& $a[0];
This line means that both $a[0] and $a[1] become references that point
to the same value. And when you do $b=$a;, $b recieves copies of these
references, so the result you get is expected and correct.
Previous Comments:
------------------------------------------------------------------------
[2006-06-26 12:55:36] andrea dot busia at axis-sv dot it
Because for a mistake "Actual result" had to be "Expected result" and
"Expected result" had to be "Actual result".
------------------------------------------------------------------------
[2006-06-26 12:52:10] andrea dot busia at axis-sv dot it
Description:
------------
First problem: If I Create an array setting an element to a string and
another element as a reference to the first, then copy the array into
an other variable, if i modify the second variable also the original
array is modified.
Second problem:
why the second code line ($a[0]="foo";) produces
[0]=>
&string(3) "foo"
instead of
[0]=>
string(3) "foo"
Thanks
Andrea Busia
Reproduce code:
---------------
<?
$a=array();
$a[0]="foo";
$a[1] =& $a[0];
var_dump($a);
$b=$a;
$b[0]="bar";
var_dump($a);
?>
Expected result:
----------------
array(2) {
[0]=>
string(3) "foo"
[1]=>
&string(3) "foo"
}
array(2) {
[0]=>
string(3) "foo"
[1]=>
&string(3) "foo"
}
Actual result:
--------------
array(2) {
[0]=>
&string(3) "foo"
[1]=>
&string(3) "foo"
}
array(2) {
[0]=>
&string(3) "bar"
[1]=>
&string(3) "bar"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=37917&edit=1