|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-06-10 20:46 UTC] tomas_matousek at hotmail dot com
Description:
------------
Create an array $b and set some of its item to reference the array itself by =& operator. Then assign this array to some other variable. This assignment (*) makes something wrong in the array $b because if you change $b's items after this assignment the structure of array $b is changed.
However, if that assignment (*) doesn't take place the behavior is correct.
Reproduce code:
---------------
$b = array(1,2,3,4);
$b[4] =& $b;
// this assignment probably makes changes to $b's structure
$c = $b;
$b[1] = 'X';
$b[4][1] = 'Y';
$b[4][4][1] = 'Z';
print_r($b);
Expected result:
----------------
Array
(
[0] => 1
[1] => Z
[2] => 3
[3] => 4
[4] => Array
*RECURSION*
)
Actual result:
--------------
Array
(
[0] => 1
[1] => X
[2] => 3
[3] => 4
[4] => Array
(
[0] => 1
[1] => Y
[2] => 3
[3] => 4
[4] => Array
(
[0] => 1
[1] => Z
[2] => 3
[3] => 4
[4] => Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => Array
*RECURSION*
)
)
)
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 04:00:01 2025 UTC |
Results on RC3: Array ( [0] => 1 [1] => Z [2] => 3 [3] => 4 [4] => Array ( [0] => 1 [1] => Z [2] => 3 [3] => 4 [4] => Array *RECURSION* ) ) Seems as aspected resultsPerhaps this can help track down the problem. php 5.0.0RC3-dev: [snip access array ouptut] [4] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => Array *RECURSION* ) ) ) ) /usr/home/curt/cvs/php/php-src/Zend/zend_execute.c(662) : Freeing 0x083C4208 (16 bytes), script=2873.php /usr/home/curt/cvs/php/php-src/Zend/zend_execute.c(3413) : Freeing 0x083C4150 (35 bytes), script=2873.php /usr/home/curt/cvs/php/php-src/Zend/zend_hash.c(377) : Actual location (location was relayed) Last leak repeated 3 times /usr/home/curt/cvs/php/php-src/Zend/zend_execute.c(3382) : Freeing 0x083C410C (16 bytes), script=2873.php Last leak repeated 3 times /usr/home/curt/cvs/php/php-src/Zend/zend_execute.c(3362) : Freeing 0x083C4A6C (32 bytes), script=2873.php /usr/home/curt/cvs/php/php-src/Zend/zend_hash.c(157) : Actual location (location was relayed) Last leak repeated 1 time === Total 11 memory leaks detected ===