|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-06-19 08:02 UTC] mike@php.net
[2006-08-08 17:09 UTC] ale at estudionemo dot com
[2006-12-31 21:19 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 06:00:01 2025 UTC |
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"