#49386 [Opn->Bgs]: foreach with reference causes funny behaviour

From: Date: Thu, 27 Aug 2009 11:41:12 +0000
Subject: #49386 [Opn->Bgs]: foreach with reference causes funny behaviour
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-141616@lists.php.net to get a copy of this message
 ID:               49386
 Updated by:       colder@php.net
 Reported By:      ingo dot aengenheister at gmx dot de
-Status:           Open
+Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: Windows Vista
 PHP Version:      5.3.0
 New Comment:

Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system
is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

foreach by ref will not delete the reference after foreach is finished,
meaning $b is still a ref to the last element after the first foreach,
which you then overwrite with the values of the second array.


Previous Comments:
------------------------------------------------------------------------

[2009-08-27 11:38:36] ingo dot aengenheister at gmx dot de

Description:
------------
is it a bug or a feature ?

Reproduce code:
---------------
<?php

$a = array('a','b','c','d','e');
foreach($a as &$b){}

foreach($a as $b){
    echo $b; // last element lost in space, next to last element
appears 2 times
}

?>

Expected result:
----------------
abcde

Actual result:
--------------
abcdd


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49386&edit=1



Thread (5 messages)

« previous php.bugs (#141616) next »