ID: 39011
Comment by: plyrvt at mail dot ru
Reported By: php_bug dot email at email dot digiways dot com
Status: Open
Bug Type: Arrays related
Operating System: Windows XP
PHP Version: 5.1.6
New Comment:
Confirm with 5.1.6:
<?php
$a['b']='foo';
function boo($_params){
$_params['b'] = 'bar';
echo $a['b'];
}
foreach($a as $key => &$val) {} // ?!
echo $a['b'];
boo($a);
echo $a['b'];
?>
If you comment out `foreach` loop or remove & near `$val`, code works
OK. Loop does nothing and $val is *never* mentioned in code elsewhere.
Previous Comments:
------------------------------------------------------------------------
[2006-10-01 21:37:06] php_bug dot email at email dot digiways dot com
This problem affects all the arrays and not just the $_GET one. Please
note that $value is not reused outside of the foreach loop. Effectively
this renders foreach by reference useless.
Another very simple script which reproduces the problem:
$myarray = array( 'mykey' => 'foo' );
function doit($tmp) { $tmp['mykey'] = 'bar'; }
foreach($myarray as $key => &$value) {}
echo $myarray['mykey']."\n";
doit($myarray);
echo $myarray['mykey']."\n";
and outputs
foo
bar
instead of
foo
foo
------------------------------------------------------------------------
[2006-10-01 21:00:11] php_bug dot email at email dot digiways dot com
Where exactly is this behaviour documented? Can you point to the
documentation page as I failed to find this.
Also, another defect http://bugs.php.net/bug.php?id=29992 which was
referenced here is a different problem. In my case I do not reuse the
reference variable $value .
------------------------------------------------------------------------
[2006-10-01 20:39:17] [EMAIL PROTECTED]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php
bogus
------------------------------------------------------------------------
[2006-10-01 20:24:34] judas dot iscariote at gmail dot com
this is the expected behaviuor, and not a bug. :P
the reasons are clearly explained by gardan at gmx dot de on this
report, please do a search before reporting
http://bugs.php.net/bug.php?id=29992
------------------------------------------------------------------------
[2006-10-01 20:13:53] sitnikov at infonet dot ee
confirmed with PHP Version 5.2.0RC5-dev
------------------------------------------------------------------------
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/39011
--
Edit this bug report at http://bugs.php.net/?id=39011&edit=1