|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 17:00:02 2025 UTC | 
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 elseI 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.