ID: 31114
Comment by: fedotov dot leon at gmail dot com
Reported By: clemens at gutweiler dot net
Status: Assigned
Bug Type: Arrays related
Operating System: Linux 2.4.27
PHP Version: 4CVS
Assigned To: andi
New Comment:
I stumbled across another werd behavior related to this bug:
[php]
$var = array(
"a" => array("foo"),
"b" => array("fox"),
"c" => "x"
);
foreach($var as $key => $val) {
echo "no matter what happends".$val;
}
/* $var is array(
"a" => array("foo"),
"b" => array("fox"),
"c" => "foo"
);
*/
[/php]
Previous Comments:
------------------------------------------------------------------------
[2005-05-17 12:01:49] [EMAIL PROTECTED]
Works fine in PHP 5..
------------------------------------------------------------------------
[2004-12-16 22:32:14] [EMAIL PROTECTED]
I just tested this on PHP 4.3.1 and 4.3.2 and it behaves in the same
way, making this a non-critical bug and not related to the foreach
speed-up patch. Assigning to Andi, as he might have a clue why this
happens. The new foreach code is definitely not the problem here.
------------------------------------------------------------------------
[2004-12-16 13:07:17] [EMAIL PROTECTED]
(The only bug here is that it doesn't give a warning, using $k for both
key and value is not supposed to work!)
------------------------------------------------------------------------
[2004-12-16 11:41:54] [EMAIL PROTECTED]
I don't think this was ever supposed to work.
------------------------------------------------------------------------
[2004-12-16 10:44:05] clemens at gutweiler dot net
Description:
------------
foreach modifies an array, if key and value are the same variable.
see reproduction code.
Reproduce code:
---------------
<?php
$foo = array( 'foo' => 'bar', 'dings' => 'dongs' );
foreach( $foo as $k => $k ) {}
var_dump( $foo );
?>
array(2) {
["foo"]=>
string(5) "dings"
["dings"]=>
NULL
}
Expected result:
----------------
array(2) {
["foo"]=>
string(3) "bar"
["dings"]=>
string(5) "dongs"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=31114&edit=1