Skip to content

Commit 0cd06d1

Browse files
committed
Merge branch 'PHP-8.0'
* Fix arginfo/ZPP mismatch for simplexml_import_dom
2 parents 39876ba + cb84e5c commit 0cd06d1

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

ext/simplexml/simplexml.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,27 +2619,32 @@ PHP_FUNCTION(simplexml_import_dom)
26192619
RETURN_THROWS();
26202620
}
26212621

2622-
object = Z_LIBXML_NODE_P(node);
2623-
26242622
nodep = php_libxml_import_node(node);
26252623

2626-
if (nodep) {
2627-
if (nodep->doc == NULL) {
2628-
php_error_docref(NULL, E_WARNING, "Imported Node must have associated Document");
2629-
RETURN_NULL();
2630-
}
2631-
if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
2632-
nodep = xmlDocGetRootElement((xmlDocPtr) nodep);
2633-
}
2624+
if (!nodep) {
2625+
zend_argument_type_error(1, "must be of type SimpleXMLElement|DOMNode, %s given", zend_zval_type_name(node));
2626+
RETURN_THROWS();
2627+
}
2628+
2629+
if (nodep->doc == NULL) {
2630+
php_error_docref(NULL, E_WARNING, "Imported Node must have associated Document");
2631+
RETURN_NULL();
2632+
}
2633+
2634+
if (nodep->type == XML_DOCUMENT_NODE || nodep->type == XML_HTML_DOCUMENT_NODE) {
2635+
nodep = xmlDocGetRootElement((xmlDocPtr) nodep);
26342636
}
26352637

2636-
if (nodep && nodep->type == XML_ELEMENT_NODE) {
2638+
if (nodep->type == XML_ELEMENT_NODE) {
26372639
if (!ce) {
26382640
ce = sxe_class_entry;
26392641
fptr_count = NULL;
26402642
} else {
26412643
fptr_count = php_sxe_find_fptr_count(ce);
26422644
}
2645+
2646+
object = Z_LIBXML_NODE_P(node);
2647+
26432648
sxe = php_sxe_object_new(ce, fptr_count);
26442649
sxe->document = object->document;
26452650
php_libxml_increment_doc_ref((php_libxml_node_object *)sxe, nodep->doc);

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(DOMNode $node, ?string $class_name = SimpleXMLElement::class): ?SimpleXMLElement {}
9+
function simplexml_import_dom(SimpleXMLElement|DOMNode $node, ?string $class_name = SimpleXMLElement::class): ?SimpleXMLElement {}
1010

1111
class SimpleXMLElement implements Stringable, Countable, RecursiveIterator
1212
{

ext/simplexml/simplexml_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 4e4844b9cbac53c3fff061192f7e1ff703ac2f8c */
2+
* Stub hash: 6f71b9fa3dd098b1401be8c659d03041f7d361c1 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_simplexml_load_file, 0, 1, SimpleXMLElement, MAY_BE_FALSE)
55
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
@@ -18,7 +18,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_simplexml_load_string, 0, 1,
1818
ZEND_END_ARG_INFO()
1919

2020
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_simplexml_import_dom, 0, 1, SimpleXMLElement, 1)
21-
ZEND_ARG_OBJ_INFO(0, node, DOMNode, 0)
21+
ZEND_ARG_OBJ_TYPE_MASK(0, node, SimpleXMLElement|DOMNode, 0, NULL)
2222
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, class_name, IS_STRING, 1, "SimpleXMLElement::class")
2323
ZEND_END_ARG_INFO()
2424

0 commit comments

Comments
 (0)