Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/dom/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -2096,6 +2096,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_OBJ(docp, id, xmlDocPtr, 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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be another test for passing a enum?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An enum cannot pass the instanceof_function(ce, basece) check. i.e. you'll get Argument #2 ($extendedClass) must be a class name derived from DOMElement or null, **enum name here** given.

} catch (ValueError $e) {
echo "ValueError: ", $e->getMessage(), "\n";
}

$dom->createElement("foo");

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