[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Thu, 19 Nov 2026 23:16:02 +0000
Subject: [php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-143934@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-11-19T18:14:21-05:00 Commit: https://github.com/php/php-src/commit/3b434cf95f3a3e841910d4b363f45932717cd25e Raw diff: https://github.com/php/php-src/commit/3b434cf95f3a3e841910d4b363f45932717cd25e.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: ext/simplexml: Resolve constants of user classes before instantiation Changed paths: A ext/simplexml/tests/simplexml_load_class_constants.phpt M NEWS M ext/simplexml/simplexml.c Diff: diff --git a/NEWS b/NEWS index 1bc0372d019e..5b2afe33ac11 100644 --- a/NEWS +++ b/NEWS @@ -143,6 +143,13 @@ PHP NEWS . Fixed session upload progress to respect session.use_only_cookies. (jorgsowa) +- SimpleXML: + . Fixed a crash with opcache when simplexml_load_string(), + simplexml_load_file() or simplexml_import_dom() is given a class whose + property defaults use constants. A class with an undefined constant now + throws an Error instead of returning an object with unresolved values. + (Ilia Alshanetsky) + - Sockets: . Fixed socket_addrinfo_lookup() rejecting an empty packed hints array. (lacatoire) diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index 367fe37c377f..26450e95d3cc 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -2277,6 +2277,10 @@ PHP_FUNCTION(simplexml_load_file) RETURN_THROWS(); } + if (ce && UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { + RETURN_THROWS(); + } + PHP_LIBXML_SANITIZE_GLOBALS(read_file); docp = xmlReadFile(filename, NULL, (int)options); PHP_LIBXML_RESTORE_GLOBALS(read_file); @@ -2331,6 +2335,10 @@ PHP_FUNCTION(simplexml_load_string) RETURN_THROWS(); } + if (ce && UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { + RETURN_THROWS(); + } + PHP_LIBXML_SANITIZE_GLOBALS(read_memory); docp = xmlReadMemory(data, (int)data_len, NULL, NULL, (int)options); PHP_LIBXML_RESTORE_GLOBALS(read_memory); @@ -2641,6 +2649,10 @@ PHP_FUNCTION(simplexml_import_dom) RETURN_THROWS(); } + if (ce && UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { + RETURN_THROWS(); + } + nodep = php_libxml_import_node(node); if (!nodep) { diff --git a/ext/simplexml/tests/simplexml_load_class_constants.phpt b/ext/simplexml/tests/simplexml_load_class_constants.phpt new file mode 100644 index 000000000000..2614c7d77dca --- /dev/null +++ b/ext/simplexml/tests/simplexml_load_class_constants.phpt @@ -0,0 +1,73 @@ +--TEST-- +simplexml_load_string(), simplexml_load_file() and simplexml_import_dom() resolve constants of the given class +--EXTENSIONS-- +simplexml +dom +--INI-- +opcache.enable_cli=1 +--FILE-- +<?php +const VALUE = 42; +const STR = "a"; + +class StringElement extends SimpleXMLElement { + public $var = VALUE; +} +class FileElement extends SimpleXMLElement { + public $var = VALUE; +} +class ImportedElement extends SimpleXMLElement { + public $var = VALUE; +} +class UndefElement extends SimpleXMLElement { + public $var = UNDEF_CONST; +} +class TypedElement extends SimpleXMLElement { + public int $var = STR; +} +class ConstElement extends SimpleXMLElement { + const C = UNDEF_CONST; +} + +$file = __DIR__ . "/book.xml"; +$dom = new DOMDocument(); +$dom->loadXML("<root/>"); + +echo get_class(simplexml_load_string("<root/>", StringElement::class)), PHP_EOL; +echo get_class(simplexml_load_file($file, FileElement::class)), PHP_EOL; +echo get_class(simplexml_import_dom($dom, ImportedElement::class)), PHP_EOL; + +$loaders = [ + fn($class) => simplexml_load_string("<root/>", $class), + fn($class) => simplexml_load_file($file, $class), + fn($class) => simplexml_import_dom($dom, $class), +]; +foreach ($loaders as $load) { + try { + $load(UndefElement::class); + } catch (Error $e) { + echo $e::class, ": ", $e->getMessage(), PHP_EOL; + } +} + +try { + simplexml_load_string("<root/>", TypedElement::class); +} catch (TypeError $e) { + echo $e::class, ": ", $e->getMessage(), PHP_EOL; +} + +try { + simplexml_load_string("<root/>", ConstElement::class); +} catch (Error $e) { + echo $e::class, ": ", $e->getMessage(), PHP_EOL; +} +?> +--EXPECT-- +StringElement +FileElement +ImportedElement +Error: Undefined constant "UNDEF_CONST" +Error: Undefined constant "UNDEF_CONST" +Error: Undefined constant "UNDEF_CONST" +TypeError: Cannot assign string to property TypedElement::$var of type int +Error: Undefined constant "UNDEF_CONST"

« previous php.cvs (#143934) next »