Skip to content

Commit 4bd6356

Browse files
authored
Fix argument type of simplexml_import_dom (#13170)
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.
1 parent 8cc472d commit 4bd6356

File tree

7 files changed

+12
-7
lines changed

7 files changed

+12
-7
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ SimpleXML:
109109
. Fixed bug GH-12208 (SimpleXML infinite loop when a cast is used inside a
110110
foreach). (nielsdos)
111111
. Fixed bug #55098 (SimpleXML iteration produces infinite loop). (nielsdos)
112+
. Fix signature of simplexml_import_dom(). (nielsdos)
112113

113114
SNMP:
114115
. Removed the deprecated inet_ntoa call support. (David Carlier)

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ PHP 8.4 UPGRADE NOTES
102102
cause an infinite loop because it destroyed the current iterator data.
103103
This is no longer the case as a consequence of the bugfixes for GH-12192,
104104
GH-12208, #55098.
105+
. Calling simplexml_import_dom() with a non-XML object now throws a TypeError
106+
instead of a ValueError.
105107

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

138142
========================================
139143
2. New Features

ext/simplexml/simplexml.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2567,7 +2567,7 @@ PHP_FUNCTION(simplexml_import_dom)
25672567
nodep = php_libxml_import_node(node);
25682568

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

ext/simplexml/simplexml.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function simplexml_load_file(string $filename, ?string $class_name = SimpleXMLEl
66

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

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

1111
/** @not-serializable */
1212
class SimpleXMLElement implements Stringable, Countable, RecursiveIterator

ext/simplexml/simplexml_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/xsl/tests/xsltprocessor_importStylesheet-invalidparam.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $xslt = new XSLTProcessor();
99
$dummy = new stdClass();
1010
try {
1111
var_dump($xslt->importStylesheet($dummy));
12-
} catch (ValueError $e) {
12+
} catch (TypeError $e) {
1313
echo $e->getMessage(), "\n";
1414
}
1515

ext/xsl/xsltprocessor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ PHP_METHOD(XSLTProcessor, importStylesheet)
147147
doc = nodep->doc;
148148
}
149149
if (doc == NULL) {
150-
zend_argument_value_error(1, "must be a valid XML node");
150+
zend_argument_type_error(1, "must be a valid XML node");
151151
RETURN_THROWS();
152152
}
153153

@@ -232,7 +232,7 @@ static xmlDocPtr php_xsl_apply_stylesheet(zval *id, xsl_object *intern, xsltStyl
232232
}
233233

234234
if (doc == NULL) {
235-
zend_argument_value_error(1, "must be a valid XML node");
235+
zend_argument_type_error(1, "must be a valid XML node");
236236
return NULL;
237237
}
238238

0 commit comments

Comments
 (0)