Skip to content

Fix argument type of simplexml_import_dom #13170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2024
Merged
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
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,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