#35835 [Opn]: next() does not work on referenced arrays

From: Date: Thu, 29 Dec 2005 03:41:34 +0000
Subject: #35835 [Opn]: next() does not work on referenced arrays
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-91202@lists.php.net to get a copy of this message
 ID:               35835
 User updated by:  ghetalion at ghetalion dot com
 Reported By:      ghetalion at ghetalion dot com
 Status:           Open
 Bug Type:         Arrays related
 Operating System: Windows XP
 PHP Version:      4.4.1
 New Comment:

I always make some stupid mistake when posting on the internet....

 echo &yup;
should be
 echo $yup;


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

[2005-12-29 04:39:34] ghetalion at ghetalion dot com

Description:
------------
When using next() on a referenced array, the internal pointer is not
moved at all.

Reproduce code:
---------------
function &getEach(&$a)
{
        if(($elem = current($a)) !== FALSE)
        {
                $k = key($a);
                next($a);
                return $a[$k];
        }
        return false;
} 

$alist = array("a", "b", "c");
for(reset($alist); $yup =& getEach($alist);)
{
 echo &yup;
}

Expected result:
----------------
abc

Actual result:
--------------
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(etc)


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


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


Thread (5 messages)

« previous php.bugs (#91202) next »