[php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Ilia Alshanetsky | Date: | Tue, 29 Sep 2026 18:55:18 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141719@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-09-29T14:53:12-04:00
Commit: https://github.com/php/php-src/commit/65f7c719a349de55852f1725165b70ff9dcdbb38
Raw diff: https://github.com/php/php-src/commit/65f7c719a349de55852f1725165b70ff9dcdbb38.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
ext/libxml: Keep SimpleXML children alive across reconstruction
Changed paths:
A ext/simplexml/tests/reconstruct_with_retained_child.phpt
M NEWS
M ext/libxml/libxml.c
Diff:
diff --git a/NEWS b/NEWS
index 478e2291210e..19c3b30ee956 100644
--- a/NEWS
+++ b/NEWS
@@ -64,6 +64,10 @@ PHP NEWS
- PDO_PGSQL:
. Fixed crash when a persistent connection fails. (KentarouTakeda)
+- SimpleXML:
+ . Fixed reconstructing a SimpleXMLElement freeing a child element that
+ another variable still references. (Ilia Alshanetsky)
+
- Zip:
. Fixed bug GH-23899 (Assertion failure when a cancel callback returns an
invalid type during shutdown). (Weilin Du)
diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c
index 361339a3466f..e53746379428 100644
--- a/ext/libxml/libxml.c
+++ b/ext/libxml/libxml.c
@@ -1466,6 +1466,7 @@ PHP_LIBXML_API void php_libxml_node_decrement_resource(php_libxml_node_object
*o
obj_node->_private = NULL;
}
}
+ object->node = NULL;
}
if (object != NULL && object->document != NULL) {
/* Safe to call as if the resource were freed then doc pointer is NULL */
diff --git a/ext/simplexml/tests/reconstruct_with_retained_child.phpt
b/ext/simplexml/tests/reconstruct_with_retained_child.phpt
new file mode 100644
index 000000000000..c6a1cb418089
--- /dev/null
+++ b/ext/simplexml/tests/reconstruct_with_retained_child.phpt
@@ -0,0 +1,19 @@
+--TEST--
+SimpleXMLElement reconstruction with a retained child
+--EXTENSIONS--
+simplexml
+--FILE--
+<?php
+$xml = simplexml_load_string('<root><child>old</child></root>');
+$child = $xml->child;
+
+$xml->__construct('<root><new>new</new></root>');
+
+var_dump((string) $xml->new);
+var_dump((string) $child);
+var_dump($child->asXML());
+?>
+--EXPECT--
+string(3) "new"
+string(3) "old"
+string(18) "<child>old</child>"