#45890 [Opn->Bgs]: Memory exhausted while trying to iterate simplexml object property

[email protected]
Newsgroups php.bugs
Message-ID <[email protected]>
 ID:               45890
 Updated by:       [email protected]
 Reported By:      vans9 at yandex dot ru
-Status:           Open
+Status:           Bogus
 Bug Type:         SimpleXML related
 Operating System: FreeBSD 6.2
 PHP Version:      5.2.6
 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2008-08-22 08:06:14] vans9 at yandex dot ru

And if you look at the output, printing the <class> entries is
expected, but class-sub-entries are printed with current, and next.

------------------------------------------------------------------------

[2008-08-22 07:58:01] 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.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45890&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.