ID: 41603 User updated by: david at terrainferno dot net Reported By: david at terrainferno dot net Status: Bogus Bug Type: Arrays related Operating System: Windows XP PHP Version: 5.2.3 New Comment:
Appologies, I can now see how the behavior is occuring. Thanks for point ing me in the right direction. Previous Comments: ------------------------------------------------------------------------ [2007-06-06 08:16:17] [EMAIL PROTECTED] Read detailed explanation here: http://bugs.php.net/bug.php?id=29992 BOTH your examples work the very same way and produce the very same result. ------------------------------------------------------------------------ [2007-06-06 07:19:59] david at terrainferno dot net How could this possibly be expected behaviour. This isnt a feature that happens every time and can be explained away (I would understand if this was some bizarre feature of referencing arrays), as shown by the 2 test cases provided, they are identical apart from the name given to the reference variable, just changing the name changes the result, how can this possibly be expected behaviour??? ------------------------------------------------------------------------ [2007-06-06 06:15:13] [EMAIL PROTECTED] Please search the database before reporting. ------------------------------------------------------------------------ [2007-06-06 04:28:21] judas dot iscariote at gmail dot com This is the expected beahviuor, this issue has been reported counteless of time, and explained to death. for an explanation see comment by gardan at gmx dot de here: http://bugs.php.net/bug.php?id=29992 I wonder why does not raise an E_NOTICE "shooting yourself in the foot with references" :-) ------------------------------------------------------------------------ [2007-06-05 22:12:56] david at terrainferno dot net Description: ------------ This was reported in 2006 in the foreach user comment http://uk.php.net/manual/en/control-structures.foreach.php#60806, but using php5 using references in a foreach loop, manipulating the last element in an array seems to have no effect, the reference is referred to as $v. Reproduce code: --------------- // fails to work as expected $ar = array(1,2,3,4); foreach ($ar as &$v){ $v *= 2; } foreach($ar as $v){ echo $v . '<br>'; } // works correctly $ar = array(1,2,3,4); foreach ($ar as &$o){ $o *= 2; } foreach($ar as $o){ echo $o . '<br>'; } Expected result: ---------------- 2 4 6 8 Actual result: -------------- 2 4 6 6 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41603&edit=1