#37817 [NEW]: bad foreach loop the second time with simple xml

From: Date: Thu, 15 Jun 2006 12:24:42 +0000
Subject: #37817 [NEW]: bad foreach loop the second time with simple xml
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-98394@lists.php.net to get a copy of this message
From: ecervetti at ch-hyeres dot fr Operating system: Linux mandriva 2006 PHP version: 5.1.4 PHP Bug Type: SimpleXML related Bug description: bad foreach loop the second time with simple xml Description: ------------ I try to access a particular element of xml data with the foreach($xml->name_of_element ....) syntax. But I don't know if this element exists. When the element don't exists, no problem the first time; It don't goes inside the loop. But If I call the same loop a second time, it goes inside the loop, as if the element exists. Reproduce code: --------------- $string = "<data><typebal1>pim</typebal1><typebal2>poom</typebal2></data>"; $xml = simplexml_load_string($string); foreach($xml->typebal3 as $bal) { print "<br />I should not be here<br />"; } foreach($xml->typebal3 as $bal) { print "<br />I should either not be here<br />"; } //this script renders "I should either not be here" Expected result: ---------------- this script should not print anything Actual result: -------------- this script renders "I should either not be here" -- Edit bug report at http://bugs.php.net/?id=37817&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37817&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=37817&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37817&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=37817&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=37817&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=37817&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=37817&r=needscript Try newer version: http://bugs.php.net/fix.php?id=37817&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=37817&r=support Expected behavior: http://bugs.php.net/fix.php?id=37817&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=37817&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=37817&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=37817&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37817&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=37817&r=dst IIS Stability: http://bugs.php.net/fix.php?id=37817&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=37817&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=37817&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=37817&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=37817&r=mysqlcfg

« previous php.bugs (#98394) next »