com php-src: Fix bug #72957: ext/simplexml/simplexml.c ext/simplexml/tests/bug72957.phpt
| From: | Anatol Belski | Date: | Tue, 30 Aug 2016 11:38:54 +0000 |
| Subject: | com php-src: Fix bug #72957: ext/simplexml/simplexml.c ext/simplexml/tests/bug72957.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94157@lists.php.net to get a copy of this message | ||
Commit: 345b96c4a3f20f4237028005b8189c2ab480e467
Author: Nikita Popov <nikic@php.net> Tue, 30 Aug 2016 13:05:53 +0200
Committer: Anatol Belski <ab@php.net> Tue, 30 Aug 2016 13:38:54 +0200
Parents: f6d02733fdb02fb06c74efe6c9431905a6e0d39d
Branches: PHP-7.0.11
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=345b96c4a3f20f4237028005b8189c2ab480e467
Log:
Fix bug #72957
(cherry picked from commit bfd4277008d3bda95ff5b418c60d41d50488d33b)
Bugs:
https://bugs.php.net/72957
Changed paths:
M ext/simplexml/simplexml.c
A ext/simplexml/tests/bug72957.phpt
Diff:
diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c
index 7c1e687..8e9f7b2 100644
--- a/ext/simplexml/simplexml.c
+++ b/ext/simplexml/simplexml.c
@@ -356,7 +356,10 @@ long_dim:
_node_as_zval(sxe, node, rv, newtype, name, sxe->iter.nsprefix, sxe->iter.isprefix);
}
#else
- _node_as_zval(sxe, node, rv, SXE_ITER_ELEMENT, name, sxe->iter.nsprefix,
sxe->iter.isprefix);
+ /* In BP_VAR_IS mode only return a proper node if it actually exists. */
+ if (type != BP_VAR_IS || sxe_find_element_by_name(sxe, node->children, (xmlChar *) name)) {
+ _node_as_zval(sxe, node, rv, SXE_ITER_ELEMENT, name, sxe->iter.nsprefix,
sxe->iter.isprefix);
+ }
#endif
}
}
@@ -801,17 +804,8 @@ static int sxe_prop_dim_exists(zval *object, zval *member, int check_empty,
zend
node = php_sxe_get_first_node(sxe, node);
}
node = sxe_get_element_by_offset(sxe, Z_LVAL_P(member), node, NULL);
- }
- else {
- node = node->children;
- while (node) {
- xmlNodePtr nnext;
- nnext = node->next;
- if (node->type == XML_ELEMENT_NODE && !xmlStrcmp(node->name, (xmlChar
*)Z_STRVAL_P(member)) && match_ns(sxe, node, sxe->iter.nsprefix, sxe->iter.isprefix))
{
- break;
- }
- node = nnext;
- }
+ } else {
+ node = sxe_find_element_by_name(sxe, node->children, (xmlChar *)Z_STRVAL_P(member));
}
if (node) {
exists = 1;
diff --git a/ext/simplexml/tests/bug72957.phpt b/ext/simplexml/tests/bug72957.phpt
new file mode 100644
index 0000000..29ca69f
--- /dev/null
+++ b/ext/simplexml/tests/bug72957.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Bug #72957: Null coalescing operator doesn't behave as expected with SimpleXMLElement
+--SKIPIF--
+<?php if (!extension_loaded("simplexml")) print "skip simplexml extension is not
loaded"; ?>
+--FILE--
+<?php
+
+$xml = new SimpleXMLElement('<root><elem>Text</elem></root>');
+
+echo 'elem2 is: ' . ($xml->elem2 ?? 'backup string') . "\n";
+echo 'elem2 is: ' . (isset($xml->elem2) ? $xml->elem2 : 'backup string')
. "\n";
+
+?>
+--EXPECT--
+elem2 is: backup string
+elem2 is: backup string