ID:               29687
 Updated by:       [EMAIL PROTECTED]
 Reported By:      jakub dot phpbug at horky dot net
-Status:           Open
+Status:           Feedback
 Bug Type:         Scripting Engine problem
 Operating System: *
 PHP Version:      6CVS-2006-04-28 (snap)
 New Comment:

Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi




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

[2006-04-28 19:21:51] jakub dot phpbug at horky dot net

(Also note that unlike bug #28939, there are _referenced_ arrays in
question.)

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

[2006-04-28 19:10:44] jakub dot phpbug at horky dot net

Please review the bug. It ISN'T bogus indeed, although it appears so.
The code snippet provided proves that the behavior is really incorrect.
Admit that when you only "touch" the array (by read-only function such
as key()), you lose your reference-passing? More, you don't lose it in
current cycle but in the NEXT cycle and subsequent? Hmm...

I tested it on today's snap and still the same behavior.

I'm really looking forward to the moment when I can remove the
workaround from all reference-passed foreachs from all of my projects...
thanks.

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

[2005-06-19 02:00:07] [EMAIL PROTECTED]

See bug #28939


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

[2004-08-15 15:19:47] jakub dot phpbug at horky dot net

Description:
------------
A value passed inside foreach() costruct by reference does not reflect
the changes made to that value when the iterated array is touched by
some array function, like key() or current().

In example below, if you comment out the key() line, it will work OK.

I think that this bug is closely related to the bug #28939.


Reproduce code:
---------------
<?php

$array = array("NO", "NO", "NO");

foreach($array as $index => &$item)
{
  key($array); // there may be also current(), reset(),
               // first(), next(), prev(), foreach etc.
  $item = "YES";
  var_dump($item);
}

print_r($array);

?>

Expected result:
----------------
string(3) "YES"
string(3) "YES"
string(3) "YES"
Array
(
    [0] => YES
    [1] => YES
    [2] => YES
)


Actual result:
--------------
string(3) "YES"
string(3) "YES"
string(3) "YES"
Array
(
    [0] => YES
    [1] => NO
    [2] => NO
)



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


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

Reply via email to