php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #3153 while loop in consequtive calls to a function fails
Submitted: 2000-01-08 21:43 UTC Modified: 2000-01-09 00:07 UTC
From: bojanland at home dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.13 OS: Linux 2.2.6 i586
Private report: No CVE-ID: None
 [2000-01-08 21:43 UTC] bojanland at home dot com
function test() {
     global $pageinfo, $themes, $pagetheme, $pagename;

     echo "preloop";
     while (list($akey) = each($pageinfo)) {
           echo "inloop";
     }
     echo "postloop";
}

In the above example, $pageinfo and $themes are arrays of arrays while $pagetheme and $pagename are just strings.  In the above case, calling the function for the first time gives us preloop, inloop (many times) and postloop, which is fine.  However, calling it the second time right after the first, or a bit later, yields only preloop and postloop.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-01-09 00:07 UTC] rasmus at cvs dot php dot net
That would be because the $pageinfo array has not been reset between calls.  Since $pageinfo is a global array the internal array pointer is not reset between calls.
Just add a reset($pageinfo) call before that loop to fix it.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC