#40050 [Opn->Bgs]: Array assignment without references
| From: | iliaa@php.net | Date: | Sun, 07 Jan 2007 21:58:01 +0000 |
| Subject: | #40050 [Opn->Bgs]: Array assignment without references | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-107295@lists.php.net to get a copy of this message | ||
ID: 40050
Updated by: iliaa@php.net
Reported By: BenBE at omorphia dot de
-Status: Open
+Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Windows 2K
PHP Version: 5.2.0
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
.
Previous Comments:
------------------------------------------------------------------------
[2007-01-07 19:57:47] BenBE at omorphia dot de
Description:
------------
When assigning an array by-value into itself PHP will insert a
self-referencing Array into the new entry
Reproduce code:
---------------
$a = array();
$a[] =& $a;
print_r($a);
$b = array();
$b[] = $b;
print_r($b);
Expected result:
----------------
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
}
array(1) {
[0]=>
array(0) {
}
}
$b[0] should contain an empty array because $b was assigned by-value,
i.e. should get copied.
Actual result:
--------------
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
}
array(1) {
[0]=>
array(1) {
[0]=>
array(1) {
[0]=>
*RECURSION*
}
}
}
Comparing the references (see my entry regarding Spotting References)
you find that $b and $b[0] are different pointers and $b[0] is an array
like the one created in $a.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40050&edit=1