Skip to content

Commit 3be6ff6

Browse files
committed
Fix GH-16190: Using reflection to call Dom\Node::__construct causes assertion failure
Closes GH-16193.
1 parent 96ae694 commit 3be6ff6

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ PHP NEWS
3131
DOMElement->getAttributeNames()). (nielsdos)
3232
. Fixed bug GH-16151 (Assertion failure in ext/dom/parentnode/tree.c).
3333
(nielsdos)
34+
. Fixed bug GH-16190 (Using reflection to call Dom\Node::__construct
35+
causes assertion failure). (nielsdos)
3436

3537
- FPM:
3638
. Fixed bug GHSA-865w-9rf3-2wh5 (Logs from childrens may be altered).

ext/dom/node.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2548,7 +2548,7 @@ PHP_METHOD(Dom_Node, compareDocumentPosition)
25482548

25492549
PHP_METHOD(Dom_Node, __construct)
25502550
{
2551-
ZEND_UNREACHABLE();
2551+
zend_throw_error(NULL, "Cannot directly construct %s, use document methods instead", ZSTR_VAL(Z_OBJCE_P(ZEND_THIS)->name));
25522552
}
25532553

25542554
PHP_METHOD(DOMNode, __sleep)

ext/dom/tests/gh16190.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-16190 (Using reflection to call Dom\Node::__construct causes assertion failure)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
8+
$doc = Dom\XMLDocument::createEmpty();
9+
$rm = new ReflectionMethod($doc, '__construct');
10+
try {
11+
$rm->invoke($doc);
12+
} catch (Error $e) {
13+
echo $e->getMessage(), "\n";
14+
}
15+
16+
?>
17+
--EXPECT--
18+
Cannot directly construct Dom\XMLDocument, use document methods instead

0 commit comments

Comments
 (0)