php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37875 while(list() = each() ) on simplexml_element loops forever
Submitted: 2006-06-21 15:24 UTC Modified: 2007-08-25 01:00 UTC
Votes:14
Avg. Score:3.5 ± 1.2
Reproduced:6 of 6 (100.0%)
Same Version:2 (33.3%)
Same OS:2 (33.3%)
From: jona at oismail dot com Assigned:
Status: No Feedback Package: SimpleXML related
PHP Version: 5.1.4 OS: Windows 2000
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
8 + 25 = ?
Subscribe to this entry?

 
 [2006-06-21 15:24 UTC] jona at oismail dot com
Description:
------------
When doing a while (list($key, $val) = each($obj_XML) ) on a Simple XML object PHP loops forever.

Is this possibly related bug: #24945 foreach on simplexml_element loops forever?
Please note, for each works but only output the tag not the attribute.

Found on Windows 2000 running IIS with PHP5.1.4 as an ISAPI module.

Reproduce code:
---------------
<?php
$sXML = '<?xml version="1.0" encoding="ISO-8859-5"?>
<root type="input">
<username>Jona</username>
</root>';

$obj_XML = simplexml_load_string($sXML);

while (list($key, $val) = each($obj_XML) )
{
	echo $key ." - ";
	if(is_array($val) === true)
	{
		while (list($k, $v) = each($val) )
		{
			echo $k ." - ". $v;
		}
	}
	else
	{
		echo $val;
	}
	echo "<br />";
}
?>

Expected result:
----------------
@attributes - type - input
username - Jona

Actual result:
--------------
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input
@attributes - type - input

etc.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-29 18:21 UTC] tys at tvg dot ca
I'm running into the same bug but on a generic php PEAR DB object which leads me to believe this isn't specific to Simple XML objects.

PHP 5.1.2 (cgi) (built: May  1 2006 01:12:05)
mysql  Ver 14.12 Distrib 5.0.18, for pc-linux-gnu (i686) using readline 5.0


while(list($key,$val)=each($main->getData())) enters an endless loop

foreach($main->getData() as $key=>$val) works fine
 [2006-06-29 18:23 UTC] tys at tvg dot ca
Forgot to mention, the while code works on PHP verison 5.0.4 (cgi).
 [2007-06-13 02:39 UTC] pburney at lotsa dot net
I discovered this bug in one of my applications as well. In my case, the item was a simple multidimensional array/hash:

$_SESSION['prefs'] = array();

$_SESSION['prefs']['something'] = 'something else';

while (list($key, $value) = each($_SESSION['prefs'])) {

   echo $key . ' is ' . $value . "\n";

}

would just run forever printing:

something is something else
something is something else
something is something else
 [2007-08-17 20:06 UTC] jani@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows (zip):
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

For Windows (installer):

  http://snaps.php.net/win32/php5.2-win32-installer-latest.msi

Lot has changed since 5.1.4 so it's likely this is already fixed.
 [2007-08-25 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2009-08-02 13:14 UTC] bullshitemail at juno dot com
I ran into the same issue:

 while (list($key, $questi) = each (($HTTP_SESSION_VARS['scoreboard'][$cat]))) 

created an endless loop. I trouble shot it by creating: 

$a = 1;

while (list($key, $questi) = each (($HTTP_SESSION_VARS['scoreboard'][$cat])) && $a < 10) { 

a++  

By adding the variable $a I limited the loops to 10 times so that it would not crash my browser while I tried to figure out what was happening.

>>>>>>>>>>>>>>>>  THE FIX  <<<<<<<<<<<<<<<<
I found that I had an extra set of brackets that I didn't need.

while (list($key, $questi) = each ($HTTP_SESSION_VARS['scoreboard'][$cat])) 

This worked for me hope that it helps someone.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 23:01:26 2024 UTC