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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bojanland at home dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon May 13 09:01:35 2024 UTC