ID:               50161
 Updated by:       ras...@php.net
 Reported By:      marc at perkel dot com
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      5.2.11
 New Comment:

Arbitrarily deleting a reference would break a lot of code.  What you
are looking for a block-scope variables.  We do not have those in PHP.


Previous Comments:
------------------------------------------------------------------------

[2009-11-12 21:44:54] marc at perkel dot com

If it's been reported several times then you aren't listening. It is a
bug. This is why open source has a bad name because people don't fix
what is obviously a bug.

------------------------------------------------------------------------

[2009-11-12 21:36:55] j...@php.net

Already reported several times, already decided to be the correct
behavior which is also documented. 

------------------------------------------------------------------------

[2009-11-12 20:45:33] marc at perkel dot com

Description:
------------
When using foreach and looping through an array the second time if the
index variable isn't unset the results are that the referenced variables
is used as the index rather than the named variable.

The issue can be solved if when the foreach is set up that it does an
unset on the variable passed as the "as" variable. PHP should be changed
to unset the parameter passed as the index into the array.


Reproduce code:
---------------
$myarray = array("one","two","three","four");

foreach ($myarray as &$x) {
   $x = "$x -";
   print "$x\n";
}

print "\n";

foreach ($myarray as $x) {
   print "$x\n";
}


Expected result:
----------------
one -
two -
three -
four -

one -
two -
three -
four -

Actual result:
--------------
one -
two -
three -
four -

one -
two -
three -
three -


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50161&edit=1

Reply via email to