From e25afed140e453f1597519a529f0071893959a30 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 3 Oct 2024 08:34:50 +0200 Subject: [PATCH] Fix GH-16190: Using reflection to call Dom\Node::__construct causes assertion failure --- ext/dom/node.c | 2 +- ext/dom/tests/gh16190.phpt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 ext/dom/tests/gh16190.phpt diff --git a/ext/dom/node.c b/ext/dom/node.c index 803237d96fbdd..5d4f0144c67ad 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -2548,7 +2548,7 @@ PHP_METHOD(Dom_Node, compareDocumentPosition) PHP_METHOD(Dom_Node, __construct) { - ZEND_UNREACHABLE(); + zend_throw_error(NULL, "Cannot directly construct %s, use document methods instead", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name)); } PHP_METHOD(DOMNode, __sleep) diff --git a/ext/dom/tests/gh16190.phpt b/ext/dom/tests/gh16190.phpt new file mode 100644 index 0000000000000..d3d83b5eb49d7 --- /dev/null +++ b/ext/dom/tests/gh16190.phpt @@ -0,0 +1,18 @@ +--TEST-- +GH-16190 (Using reflection to call Dom\Node::__construct causes assertion failure) +--EXTENSIONS-- +dom +--FILE-- +invoke($doc); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Cannot directly construct Dom\XMLDocument, use document methods instead