ID:          41833
 Updated by:  [EMAIL PROTECTED]
 Reported By: hubert dot roksor at gmail dot com
-Status:      Open
+Status:      Assigned
 Bug Type:    SimpleXML related
 PHP Version: 5CVS-2007-06-28 (snap)
-Assigned To: 
+Assigned To: rrichards


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

[2007-06-28 02:18:58] hubert dot roksor at gmail dot com

Description:
------------
addChild() does not behave as expected(?) when used on a node that
wasn't previously declared.

In the example below, we initialize an empty tree, to which we attempt
to add a new node at "/child/grandchild" without previously adding
"child" to the tree. addChild() seems to operate on a temporary
SimpleXMLElement and the changes are never applied to the original
object/tree.

I believe that this bug is also responsible of the segfault that
happens if getName() is used on the temporary SimpleXMLElement. I was
very tempted to file this bug as a reproducible crash, but decided to
file it under SimpleXML in case it would help routing it to the
maintainer faster.


Tested on:

PHP 5.2.4-dev (cli) (built: Jun 27 2007 20:04:30)
WinXP
libxml2 2.6.26
SimpleXML Revision: 1.151.2.22.2.29

PHP 5.2.2-pl1-gentoo (cli) (built: May 24 2007 00:26:35)
libxml 2.6.27
SimpleXML Revision: 1.151.2.22.2.26

Reproduce code:
---------------
<?php

$xml = simplexml_load_string('<?xml version="1.0" encoding="utf-8"
?><root />');
$xml->child->addChild('grandchild');

echo $xml->asXML();

Expected result:
----------------
I expect SimpleXML to create "child" if it does not exist, then add
"grandchild" to that node. The output should be:

<?xml version="1.0" encoding="utf-8"?>
<root><child><grandchild/></child></root>

Actual result:
--------------
Neither node is added to the tree. The output is:

<?xml version="1.0" encoding="utf-8"?>
<root/>


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


-- 
Edit this bug report at http://bugs.php.net/?id=41833&edit=1

Reply via email to