Skip to content

Commit

Permalink
Fix argument type of simplexml_import_dom (#13170)
Browse files Browse the repository at this point in the history
It needs to be "object".
This is because first- and third-party extension can register custom
node types using `php_libxml_register_export`. So we don't know upfront
what types can be expected.

This also changes the error to a TypeError everywhere.
  • Loading branch information
nielsdos authored Jan 18, 2024
1 parent 8cc472d commit 4bd6356
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ SimpleXML:
. Fixed bug GH-12208 (SimpleXML infinite loop when a cast is used inside a
foreach). (nielsdos)
. Fixed bug #55098 (SimpleXML iteration produces infinite loop). (nielsdos)
. Fix signature of simplexml_import_dom(). (nielsdos)

SNMP:
. Removed the deprecated inet_ntoa call support. (David Carlier)
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ PHP 8.4 UPGRADE NOTES
cause an infinite loop because it destroyed the current iterator data.
This is no longer the case as a consequence of the bugfixes for GH-12192,
GH-12208, #55098.
. Calling simplexml_import_dom() with a non-XML object now throws a TypeError
instead of a ValueError.

- SPL:
. Out of bounds accesses in SplFixedArray now throw an exception of type
Expand Down Expand Up @@ -134,6 +136,8 @@ PHP 8.4 UPGRADE NOTES
. Failure to call a PHP function callback during evaluation now throws
instead of emitting a warning.
RFC: https://wiki.php.net/rfc/improve_callbacks_dom_and_xsl
. Calling XSLTProcessor::importStyleSheet() with a non-XML object now throws
a TypeError instead of a ValueError.

========================================
2. New Features
Expand Down
2 changes: 1 addition & 1 deletion ext/simplexml/simplexml.c
Original file line number Diff line number Diff line change
Expand Up @@ -2567,7 +2567,7 @@ PHP_FUNCTION(simplexml_import_dom)
nodep = php_libxml_import_node(node);

if (!nodep) {
zend_argument_type_error(1, "must be of type SimpleXMLElement|DOMNode, %s given", zend_zval_value_name(node));
zend_argument_type_error(1, "must be a valid XML node");
RETURN_THROWS();
}

Expand Down
2 changes: 1 addition & 1 deletion ext/simplexml/simplexml.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function simplexml_load_file(string $filename, ?string $class_name = SimpleXMLEl

function simplexml_load_string(string $data, ?string $class_name = SimpleXMLElement::class, int $options = 0, string $namespace_or_prefix = "", bool $is_prefix = false): SimpleXMLElement|false {}

function simplexml_import_dom(SimpleXMLElement|DOMNode $node, ?string $class_name = SimpleXMLElement::class): ?SimpleXMLElement {}
function simplexml_import_dom(object $node, ?string $class_name = SimpleXMLElement::class): ?SimpleXMLElement {}

/** @not-serializable */
class SimpleXMLElement implements Stringable, Countable, RecursiveIterator
Expand Down
4 changes: 2 additions & 2 deletions ext/simplexml/simplexml_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ $xslt = new XSLTProcessor();
$dummy = new stdClass();
try {
var_dump($xslt->importStylesheet($dummy));
} catch (ValueError $e) {
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}

Expand Down
4 changes: 2 additions & 2 deletions ext/xsl/xsltprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ PHP_METHOD(XSLTProcessor, importStylesheet)
doc = nodep->doc;
}
if (doc == NULL) {
zend_argument_value_error(1, "must be a valid XML node");
zend_argument_type_error(1, "must be a valid XML node");
RETURN_THROWS();
}

Expand Down Expand Up @@ -232,7 +232,7 @@ static xmlDocPtr php_xsl_apply_stylesheet(zval *id, xsl_object *intern, xsltStyl
}

if (doc == NULL) {
zend_argument_value_error(1, "must be a valid XML node");
zend_argument_type_error(1, "must be a valid XML node");
return NULL;
}

Expand Down

0 comments on commit 4bd6356

Please sign in to comment.