ID:               43501
 Comment by:       crrodriguez at suse dot de
 Reported By:      gerry dot spm at gmail dot com
 Status:           Open
 Bug Type:         Scripting Engine problem
 Operating System: Linux
 PHP Version:      5.2.3, 5.3CVS
 New Comment:

Right, looks like it is wrong..

Dmitry, can you please check this out ? ;-)

--TEST--
Bug #43501 foreach by reference corrupts the array
--FILE--
<?php
$foo = array(0);
foreach($foo as &$elmnt){}
var_dump($foo);
?>
--EXPECT--
array(1) {
  [0]=>
  int(0)
}


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

[2007-12-05 08:37:44] gerry dot spm at gmail dot com

Description:
------------
bug #29992 did not prove that the array was being modified by foreach,
however this code does. According to var_dump() the last element starts
as a "string" and after the foreach is a "reference to a string".

Reproduce code:
---------------
$foo = array('three', 'blind', 'mice');
var_dump($foo);
foreach($foo as &$elmnt){}
var_dump($foo);


Expected result:
----------------
array(3) {
  [0]=>
  string(5) "three"
  [1]=>
  string(5) "blind"
  [2]=>
  string(4) "mice"
}
array(3) {
  [0]=>
  string(5) "three"
  [1]=>
  string(5) "blind"
  [2]=>
  string(4) "mice"
}

Actual result:
--------------
array(3) {
  [0]=>
  string(5) "three"
  [1]=>
  string(5) "blind"
  [2]=>
  string(4) "mice"
}
array(3) {
  [0]=>
  string(5) "three"
  [1]=>
  string(5) "blind"
  [2]=>
  &string(4) "mice"
}


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


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

Reply via email to