Edit report at https://bugs.php.net/bug.php?id=55773&edit=1

 ID:                 55773
 User updated by:    Ray dot Paseur at Gmail dot com
 Reported by:        Ray dot Paseur at Gmail dot com
 Summary:            foreach issues warning with function main()
 Status:             Bogus
 Type:               Bug
 Package:            SimpleXML related
 Operating System:   Linux
 PHP Version:        5.3.8
 Block user comment: N
 Private report:     N

 New Comment:

Thanks for your comment.  I have two questions before I abandon this line of 
thinking.  First, what would you recommend to accomplish the removal of a child 
from an object based on an attribute of the child?  And second, why would a 
warning pointing to the nonexistent function main() in the line number of 
foreach() be considered "expected" behavior?  The php.net web site tells us to 
report a bug if we get a message identifying function main().  You can look it 
up. 
http://php.net/manual/en/function.main.php

Surely if this is an error in foreach() an error message might be crafted that 
gave a hint about the problem, eh?

Feel free to contact me offline if you have questions about what I posted in 
the report.  I'll be glad to try to clarify or help in any way.


Previous Comments:
------------------------------------------------------------------------
[2011-09-24 19:03:36] ahar...@php.net

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.

------------------------------------------------------------------------
[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

Reply via email to