|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-08-22 07:58 UTC] vans9 at yandex dot ru
Description:
------------
While trying to iterate SimpleXML's object property (array) with next(), memory exhausted.
Reproduce code:
---------------
$classes=new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?>
<classes>
<class>
<name>GenericClass</name>
<path>somepath</path>
</class>
<class>
<name>GenericClass2</name>
<path>somepath2</path>
</class>
<class>
<name>GenericClass3</name>
<path>somepath3</path>
</class>
</classes>
");
for ($classEntry=current($classes->class); $classEntry!==false; $classEntry=next($classes->class))
{
print_r($classEntry);
echo "\n";
}
echo 'Done smth.';
Expected result:
----------------
Expected: <class> elements of <classes> xml entry being printed.
Actual result:
--------------
Lot's of output and than "Allowed memory size of 134217728 bytes exhausted (tried to allocate 16 bytes)". Output may be ommited, but problem persists.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 13:00:02 2025 UTC |
The $classes->class isn't an array. Warning: current() expects parameter 1 to be array, object given Warning: next() expects parameter 1 to be array, object given ... Use: foreach ($classes->class as $class) { var_dump($class); } And see the examples at: http://docs.php.net/manual/en/simplexml.examples.php Thanks.