|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-07-14 23:58 UTC] jani@php.net
[2008-11-05 11:08 UTC] vrana@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 04:00:01 2025 UTC |
Description: ------------ I assign something by-reference to a variable. If I assign the same stuff again to the same variable by-value, this assignment is ignored. In the reproduce code, $bar first is a reference to $foo. $bar is modified via array_pop(). This modifies $foo, too. Then, $foo is assigned to $bar by-value. Again, $bar is modified via array_pop(). And again, $foo is modified too, which should not happen, because $bar should not be a reference to $foo any more. An unset($bar); right before the second assignment fixes the issue. Reproduce code: --------------- $foo = array(1, 2, 3, 4, 5); $bar =& $foo; array_pop($bar); var_dump($foo); $bar = $foo; array_pop($bar); var_dump($foo); Expected result: ---------------- array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) } array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) } Actual result: -------------- array(4) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) } array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }