Skip to content

Commit

Permalink
Merge branch 'PHP-8.3'
Browse files Browse the repository at this point in the history
* PHP-8.3:
  Fix registerNodeClass with abstract class crashing
  • Loading branch information
nielsdos committed Oct 13, 2023
2 parents 82c2143 + f5d1a19 commit 3ff3199
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -2072,6 +2072,10 @@ PHP_METHOD(DOMDocument, registerNodeClass)
}

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();
}
DOM_GET_THIS_INTERN(intern);
dom_set_doc_classmap(intern->document, basece, ce);
RETURN_TRUE;
Expand Down
24 changes: 24 additions & 0 deletions ext/dom/tests/registerNodeClass_abstract_class.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
--TEST--
registerNodeClass() with an abstract class should fail
--EXTENSIONS--
dom
--FILE--
<?php

abstract class Test extends DOMElement {
abstract function foo();
}

$dom = new DOMDocument;

try {
$dom->registerNodeClass("DOMElement", "Test");
} catch (ValueError $e) {
echo "ValueError: ", $e->getMessage(), "\n";
}

$dom->createElement("foo");

?>
--EXPECT--
ValueError: DOMDocument::registerNodeClass(): Argument #2 ($extendedClass) must not be an abstract class

0 comments on commit 3ff3199

Please sign in to comment.