#37410 [Opn->Ver]: foreach by reference exists outside of scope
| From: | sean@php.net | Date: | Thu, 11 May 2006 18:39:38 +0000 |
| Subject: | #37410 [Opn->Ver]: foreach by reference exists outside of scope | ||
| References: | 1 | Groups: | php.doc |
| Request: | Send a blank email to phpdoc+get-969372998@lists.php.net to get a copy of this message | ||
ID: 37410
Updated by: sean@php.net
Reported By: php at kormoc dot com
-Status: Open
+Status: Verified
Bug Type: Documentation problem
Operating System: Linux
PHP Version: Irrelevant
New Comment:
See http://www.zend.com/zend/week/week279.php#Heading1
S
Previous Comments:
------------------------------------------------------------------------
[2006-05-11 18:26:16] php at kormoc dot com
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 this bug report at http://bugs.php.net/?id=37410&edit=1