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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vans9 at yandex dot ru
New email:
PHP Version: OS:

 

 [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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 05:01:27 2025 UTC