#37410 [NEW]: foreach by reference exists outside of scope
| From: | php at kormoc dot com | Date: | Thu, 11 May 2006 18:26:16 +0000 |
| Subject: | #37410 [NEW]: foreach by reference exists outside of scope | ||
| Groups: | php.doc | ||
| Request: | Send a blank email to phpdoc+get-969372997@lists.php.net to get a copy of this message | ||
From: php at kormoc dot com
Operating system: Linux
PHP version: Irrelevant
PHP Bug Type: Documentation problem
Bug description: foreach by reference exists outside of scope
Description:
------------
Foreach by reference does not honour scope.
Basically, this was already reported at the following two bug reports:
http://bugs.php.net/bug.php?id=29992
http://bugs.php.net/bug.php?id=36240
And they were closed with bogus, saying to look at the manual.
Well, the manual doesn't talk about this issue at all, infact it seems to
say that it should work as expected.
Also, that var should not exists beyond the scope of the foreach loop, and
the developer that closed the bug seems to agree (he said for whatever
weird reason, and honestly, php should cater to the normal reasons, not
the weird ones, and anyone can get the same responce out of setting it
manually in the foreach themselves, rather then allowing the engine to do
something weird).
In anycase, this should at the very least get fixed up in the
documentation, but I still consider this a engine bug.
Reproduce code:
---------------
<?php
$array = array(1,2,3);
foreach( $array as &$item );
foreach( $array as $item );
print_r( $array );
?>
Expected result:
----------------
Array
(
[0] => 1
[1] => 2
[2] => 3
)
Actual result:
--------------
Array
(
[0] => 1
[1] => 2
[2] => 2
)
--
Edit bug report at http://bugs.php.net/?id=37410&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37410&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=37410&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37410&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37410&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=37410&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37410&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37410&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37410&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37410&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37410&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=37410&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=37410&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37410&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37410&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37410&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37410&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37410&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37410&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37410&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37410&r=mysqlcfg