Edit report at https://bugs.php.net/bug.php?id=55773&edit=1
ID: 55773 Updated by: ahar...@php.net Reported by: Ray dot Paseur at Gmail dot com Summary: foreach issues warning with function main() -Status: Open +Status: Bogus Type: Bug -Package: Class/Object related +Package: SimpleXML related Operating System: Linux PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php You're removing a child from the object whilst in the middle of iterating over it. At that point, all bets are off, really. I'm happy enough to call that expected behaviour, because I don't think there's actually anything sensible that can be done. Previous Comments: ------------------------------------------------------------------------ [2011-09-24 01:32:02] Ray dot Paseur at Gmail dot com Description: ------------ http://www.laprbass.com/RAY_xml_delete_nodes.php Outputs: Warning: main() [function.main]: Node no longer exists in /home/websitet/public_html/RAY_xml_delete_nodes.php on line 12 <?xml version="1.0"?> <category id="1" title="category 1"> <item id="b" title="item b" delete="false"/> </category> Test script: --------------- <?php // RAY_xml_delete_nodes.php error_reporting(E_ALL); echo "<pre>"; $xml = <<<XML <category id='1' title='category 1'> <item id='a' title='item a' delete='true' /> <item id='b' title='item b' delete='false' /> </category> XML; $obj = SimpleXML_Load_string($xml); $key = 0; foreach ($obj as $item) { if ($item["delete"] == 'true') unset($obj->item[$key]); $key++; } $new = $obj->asXML(); echo htmlentities($new); Expected result: ---------------- No warning message. The URL is here. http://www.laprbass.com/RAY_xml_delete_nodes.php ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55773&edit=1