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
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ PHP NEWS
- SimpleXML:
. Fixed writing to a dimension of the object returned by attributes() not
creating the attribute. (Ilia Alshanetsky)
. Fixed child elements of the element returned by
SimpleXMLElement::addChild() not being accessible by property name when
namespaces are involved. (Ilia Alshanetsky)

- Zip:
. Fixed bug GH-23276 (ZipArchive subclass storing its own stream cannot be
Expand Down
3 changes: 2 additions & 1 deletion ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1727,7 +1727,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
38 changes: 38 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,38 @@
--TEST--
SimpleXMLElement::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";

$z = new SimpleXMLElement('<p:r xmlns:p="http://example.com/p"/>');
$e = $z->addChild('kid');
$e->addChild('inner', 'z');
echo trim($z->asXML()), "\n";
echo (string) $e->inner, "\n";
var_dump(isset($e->inner));
?>
--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
<?xml version="1.0"?>
<p:r xmlns:p="http://example.com/p"><p:kid><p:inner>z</p:inner></p:kid></p:r>
z
bool(true)
Loading