#47028 [Com]: Strange foreach behavior when using references
| From: | kobieta dot ryba at gmail dot com | Date: | Thu, 15 Jan 2009 10:12:25 +0000 |
| Subject: | #47028 [Com]: Strange foreach behavior when using references | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-132886@lists.php.net to get a copy of this message | ||
ID: 47028
Comment by: kobieta dot ryba at gmail dot com
Reported By: kobieta dot ryba at gmail dot com
Status: Open
Bug Type: Scripting Engine problem
Operating System: Linux
PHP Version: 6CVS-2009-01-07 (CVS)
New Comment:
Is there anybody reading this?
Previous Comments:
------------------------------------------------------------------------
[2009-01-07 14:33:21] kobieta dot ryba at gmail dot com
Description:
------------
I've noticed strange behavior when using references and foreach loop.
It throws an error "Invalid argument supplied for foreach" but if the
code
// $ass = &$array;
is commented out, the result is as expected:
Output:
in
in
in
Reproduce code:
---------------
<?
$array = array("1", "2", "3");
$ass = &$array;
foreach($array as $k => &$v)
{
$array = false;
$v = "Test";
echo "in\n";
}
?>
Expected result:
----------------
in
in
in
Actual result:
--------------
in
Warning: Invalid argument supplied for foreach() in test.php on line 5
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=47028&edit=1