php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45890 Memory exhausted while trying to iterate simplexml object property
Submitted: 2008-08-22 07:58 UTC Modified: 2008-08-22 14:09 UTC
From: vans9 at yandex dot ru Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.2.6 OS: FreeBSD 6.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
19 - 8 = ?
Subscribe to this entry?

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-22 08:06 UTC] 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 14:09 UTC] felipe@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 08:01:27 2024 UTC