ID:               37875
 Comment by:       pburney at lotsa dot net
 Reported By:      jona at oismail dot com
 Status:           Verified
 Bug Type:         SimpleXML related
 Operating System: Windows 2000
 PHP Version:      5.1.4
 New Comment:

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


Previous Comments:
------------------------------------------------------------------------

[2006-06-29 18:23:32] tys at tvg dot ca

Forgot to mention, the while code works on PHP verison 5.0.4 (cgi).

------------------------------------------------------------------------

[2006-06-29 18:21:50] 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-21 15:24:29] 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.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=37875&edit=1

Reply via email to