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

From: Date: Fri, 20 Nov 2026 00:06:46 +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-143949@lists.php.net to get a copy of this message
Author: Ilia Alshanetsky (iliaal) Date: 2026-11-19T19:00:16-05:00 Commit: https://github.com/php/php-src/commit/4ebf1c0e8c66d04df2b12d49c36394770c93e62b Raw diff: https://github.com/php/php-src/commit/4ebf1c0e8c66d04df2b12d49c36394770c93e62b.diff Merge branch 'PHP-8.5' into PHP-8.6 * PHP-8.5: ext/dom: Resolve constants of a node class when registering it Changed paths: A ext/dom/tests/registerNodeClass_undefined_constant.phpt M NEWS M ext/dom/document.c Diff: diff --git a/NEWS b/NEWS index f294f129b637..3ccb8c0c0d2c 100644 --- a/NEWS +++ b/NEWS @@ -57,6 +57,9 @@ PHP NEWS - DOM: . Fixed bug GH-25306 (Assertion status == LXB_STATUS_OK in dom_parse_selector when lexbor allocation fails). (ndossche) + . Fixed crash when registerNodeClass() is given a class with a constant + expression that cannot be evaluated; registerNodeClass() now throws the + evaluation Error instead. (Ilia Alshanetsky) - Fileinfo: . Fixed bug GH-25051 (TrueType fonts detected as application/octet-stream diff --git a/ext/dom/document.c b/ext/dom/document.c index ccb2c08bc815..427a8f5dc08a 100644 --- a/ext/dom/document.c +++ b/ext/dom/document.c @@ -2303,9 +2303,14 @@ static void dom_document_register_node_class(INTERNAL_FUNCTION_PARAMETERS, bool } if (ce == NULL || instanceof_function(ce, basece)) { - if (UNEXPECTED(ce != NULL && (ce->ce_flags & ZEND_ACC_ABSTRACT))) { - zend_argument_value_error(2, "must not be an abstract class"); - RETURN_THROWS(); + if (ce != NULL) { + if (UNEXPECTED(ce->ce_flags & ZEND_ACC_ABSTRACT)) { + zend_argument_value_error(2, "must not be an abstract class"); + RETURN_THROWS(); + } + if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) { + RETURN_THROWS(); + } } DOM_GET_THIS_INTERN(intern); dom_set_doc_classmap(intern->document, basece, ce); diff --git a/ext/dom/tests/registerNodeClass_undefined_constant.phpt b/ext/dom/tests/registerNodeClass_undefined_constant.phpt new file mode 100644 index 000000000000..f6809932a110 --- /dev/null +++ b/ext/dom/tests/registerNodeClass_undefined_constant.phpt @@ -0,0 +1,75 @@ +--TEST-- +registerNodeClass() with a class whose constant expressions cannot be evaluated +--EXTENSIONS-- +dom +--FILE-- +<?php + +const STRING_CONSTANT = "abc"; + +class MyElement extends DOMElement { + public $x = UNDEFINED_CONSTANT; +} + +class MyTypedElement extends DOMElement { + public int $x = STRING_CONSTANT; +} + +class MyText extends DOMText { + const C = UNDEFINED_CONSTANT; +} + +class MyDocument extends DOMDocument { + public static $x = UNDEFINED_CONSTANT; +} + +class MyModernElement extends Dom\Element { + public $x = UNDEFINED_CONSTANT; +} + +function register($doc, string $base, string $class) { + try { + $doc->registerNodeClass($base, $class); + echo "$class: registered\n"; + } catch (Error $e) { + echo "$class: ", $e::class, ": ", $e->getMessage(), "\n"; + } +} + +$doc = new DOMDocument; +$doc->loadXML('<root>text<a/></root>'); +register($doc, 'DOMElement', 'MyElement'); +register($doc, 'DOMElement', 'MyTypedElement'); +register($doc, 'DOMText', 'MyText'); +register($doc, 'DOMDocument', 'MyDocument'); +$root = $doc->documentElement; +unset($doc); +var_dump(get_class($root)); +var_dump(get_class($root->firstChild)); +var_dump(get_class($root->ownerDocument)); + +$modern = Dom\XMLDocument::createFromString('<root><a/></root>'); +register($modern, 'Dom\Element', 'MyModernElement'); +var_dump(get_class($modern->documentElement)); + +define('UNDEFINED_CONSTANT', 1); +register($root->ownerDocument, 'DOMElement', 'MyElement'); +register($modern, 'Dom\Element', 'MyModernElement'); +var_dump(get_class($root->lastChild)); +var_dump(get_class($modern->documentElement->firstChild)); + +?> +--EXPECT-- +MyElement: Error: Undefined constant "UNDEFINED_CONSTANT" +MyTypedElement: TypeError: Cannot assign string to property MyTypedElement::$x of type int +MyText: Error: Undefined constant "UNDEFINED_CONSTANT" +MyDocument: Error: Undefined constant "UNDEFINED_CONSTANT" +string(10) "DOMElement" +string(7) "DOMText" +string(11) "DOMDocument" +MyModernElement: Error: Undefined constant "UNDEFINED_CONSTANT" +string(11) "Dom\Element" +MyElement: registered +MyModernElement: registered +string(9) "MyElement" +string(15) "MyModernElement"

« previous php.cvs (#143949) next »