ID:               37410
 Updated by:       [EMAIL PROTECTED]
 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

Reply via email to