php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44022 Infinite loop with each( )
Submitted: 2008-02-02 04:06 UTC Modified: 2008-02-08 23:22 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: martin at bang dot ca Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.4.8 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: martin at bang dot ca
New email:
PHP Version: OS:

 

 [2008-02-02 04:06 UTC] martin at bang dot ca
Description:
------------
Infinite loop when using a function call which returns an array in each( )



Reproduce code:
---------------
Infinite loop here (prints "1 -> 1\n" forever)

while( list( $k, $v ) = each( getTestArray() ) ) {
  echo "$k -> $v\n";
}

function getTestArray() {
  return array( "1" => "1" );
}

This works OK (prints "1 -> 1" once):

$GLOBALS['test'] = array( "1" => "1" );

while( list( $k, $v ) = each( getTestArray() ) ) {
  echo "$k -> $v\n";
}

function getTestArray() {
  return $GLOBALS['test'];
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-08 23:22 UTC] stas@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

getTestArray() is called each time anew. Since in the first example getTestArray() returns new array each time, it loops forever. 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 28 14:00:03 2025 UTC