ID:               32088
 User updated by:  karl at posmaster dot com dot au
 Reported By:      karl at posmaster dot com dot au
-Status:           Feedback
+Status:           Open
 Bug Type:         Zend Engine 2 problem
 Operating System: *
 PHP Version:      5CVS-2005-02-28
 New Comment:

Although I can use a workaround for this problem (and in the meantime I
have), this is still a bug in php isn't it?

After using unset() on the array, in the loop, the reference breaks.


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

[2005-02-28 22:57:00] [EMAIL PROTECTED]

You are modifying array in the foreach loop.
Consider using for/while instead of foreach.
See this code:
<?php
$stuff = array('one','two');
foreach ($stuff as $key => &$value) {
    $value='This should appear below in the var_dump() because $value
is passed by reference';
}
var_dump($stuff);
?>

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

[2005-02-28 22:49:56] karl at posmaster dot com dot au

- &$value is a refernce used in the foreach loop.
- If the unset is commented out, the reference to $stuff[1] as $value
on the second iteration of the loop works.
- The call to unset() on the first iteration breaks the reference

Actaul Output:
array(1) { [1]=> string(3) "two" }

Expected Output
array(1) { [1]=> string(3) "This should appear below in the var_dump()
because $value is passed by reference" }

<?php
$stuff = array('one','two');
foreach ($stuff as $key => &$value) {
        if($key==0){
            unset ($stuff[$key]);
        }else{
            $value='This should appear below in the var_dump() because $value
is passed by reference';
        }
}
var_dump($stuff);
?>

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

[2005-02-28 20:18:52] [EMAIL PROTECTED]

What reference? Please give the _EXACT_ expected result.
(and shorten the example script..)


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

[2005-02-27 22:51:05] karl at posmaster dot com dot au

No, the bug is still present.  The reference that should be present is
still broken.

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

[2005-02-25 14:30:13] [EMAIL PROTECTED]

So it's fixed and working -> closed.


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

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/32088

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

Reply via email to