php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37644 foreach(SimpleXMLElement... ittermittently continues indefinately
Submitted: 2006-05-30 16:42 UTC Modified: 2006-05-30 21:31 UTC
From: php at tothebrim dot net Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.1.4 OS: Windows XP Professional
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at tothebrim dot net
New email:
PHP Version: OS:

 

 [2006-05-30 16:42 UTC] php at tothebrim dot net
Description:
------------
This code works perfectly in version 5.1.2. I needed to upgrade in order to make use of simpleXMLElement->addChild and simpleXMLElement->addAttribute

I have attempted this with 5.1.3, 5.1.4 and 5.2 with Apache 2.0.58 and 5.2 and 6.0 with Apache 2.2 and the same problem occurs each time. Max process time is exceeded, when I trace the problem I find that the same value is returned repeatedly in foreach. I have some foreach statements that continue to work, even using a SimpleXMLElement, but others fail every time. 




Reproduce code:
---------------
function save_inputs($filename) {
	$doc = simplexml_load_file($filename);
	print "27<br/>";
	foreach($doc as $key=>$value) {
	  print "29<br/>";
	  if (sizeof($value->children()) && $value['type'] == "1") {
		print "31<br/>";
		$value['combine'] = $_POST["combine~$key"];
		print "33<br/>";
		process_rows($doc,$key, $value);
		print "35<br/>";
		} elseif($value['type'] == "1") {
		  print "37<br/>";
		  post_child_row($doc, $key, $value);
		  print "39<br/>";
		}  
	}
	$doc->asXML($filename);
}

Expected result:
----------------
Max Process Time Exceeded

Actual result:
--------------
Complete the foreach

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-30 16:54 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.


 [2006-05-30 17:03 UTC] judas dot iscariote at gmail dot com
try installing xdebug to determine what is getting into an infinite loop, and show us some code, we don't know what the
"process_rows" and "post_child_row" functions do, no magic cristal bowl to guess :-)
 [2006-05-30 17:53 UTC] php at tothebrim dot net
I was able to trace the problem to the assignment of a new value to a child. The problem code can be seen at http://tothebrim.net/php.txt

Thanks for your help,
Ben
 [2006-05-30 18:40 UTC] bjori@php.net
We still need SHORT but COMPLETE script..
 [2006-05-30 19:14 UTC] php at tothebrim dot net
I have updated the posted script, it is now complete. It can be viewed at http://tothebrim.net/php.txt

Thanks,
Ben
 [2006-05-30 20:59 UTC] rrichards@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

your logic is bad causing new nodes to be added and the document to keep growing. node creation on the fly was added in 5.1.3 so the bad logic was just not visible.
 [2006-05-30 21:31 UTC] php at tothebrim dot net
Thanks for your help. I did look carefully at the documentation, but I guess I missed something. I will alter my code then to accomodate.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 22:01:30 2024 UTC