Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ PHP NEWS
. Fixed a leak when a persistent connection failed a liveness check
with no other live PDO handle. (iliaal)

- SimpleXML:
. Fixed child elements of the element returned by SimpleXMLElement::addChild()
not being accessible by property name when namespaces are involved. (iliaal)

- Standard:
. Fixed a memory leak in array_merge_recursive() when the recursive merge of
an object converted to an array fails. (David Carlier)
Expand Down
3 changes: 2 additions & 1 deletion ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,8 @@ PHP_METHOD(SimpleXMLElement, addChild)
}
}

node_as_zval_str(sxe, newnode, return_value, SXE_ITER_NONE, localname, prefix, 0);
node_as_zval_str(sxe, newnode, return_value, SXE_ITER_NONE, localname,
newnode->ns ? newnode->ns->prefix : NULL, 1);

xmlFree(localname);
if (prefix != NULL) {
Expand Down
26 changes: 26 additions & 0 deletions ext/simplexml/tests/addChild_ns_filter_returned_element.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
SimpleXML::addChild() wrong namespace filter on returned element
--EXTENSIONS--
simplexml
--FILE--
<?php
$x = new SimpleXMLElement('<r xmlns:a="http://example.com"/>');
$c = $x->addChild('a:kid', null, 'http://example.com');
$c->addChild('inner', 'v');
echo trim($x->asXML()), "\n";
echo (string) $c->inner, "\n";
var_dump(isset($c->inner));
$y = new SimpleXMLElement('<r xmlns:a="http://example.com"/>');
$d = $y->addChild('kid', null, 'http://example.com');
$d->addChild('inner', 'w');
echo trim($y->asXML()), "\n";
echo (string) $d->inner, "\n";
?>
--EXPECT--
<?xml version="1.0"?>
<r xmlns:a="http://example.com"><a:kid><a:inner>v</a:inner></a:kid></r>
v
bool(true)
<?xml version="1.0"?>
<r xmlns:a="http://example.com"><a:kid><a:inner>w</a:inner></a:kid></r>
w
Loading