Skip to content

Commit 1602db2

Browse files
committed
Fix return type of DOMNodeList::item()
It can also return DOMNameSpaceNode :(
1 parent 21d9931 commit 1602db2

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

ext/dom/php_dom.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,8 @@ public function count(): int {}
230230

231231
public function getIterator(): Iterator {}
232232

233-
/** @tentative-return-type */
234-
public function item(int $index): ?DOMNode {}
233+
/** @return DOMNode|DOMNamespaceNode|null */
234+
public function item(int $index) {}
235235
}
236236

237237
class DOMCharacterData extends DOMNode implements DOMChildNode

ext/dom/php_dom_arginfo.h

Lines changed: 5 additions & 3 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: 9085cafc2477ac2efa9929a681251bf0f2f39879 */
2+
* Stub hash: 2931a77f1b3b92494ce05cf44c2175dfae5f777f */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 1)
55
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
@@ -135,7 +135,7 @@ ZEND_END_ARG_INFO()
135135
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_DOMNodeList_getIterator, 0, 0, Iterator, 0)
136136
ZEND_END_ARG_INFO()
137137

138-
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DOMNodeList_item, 0, 1, DOMNode, 1)
138+
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DOMNodeList_item, 0, 0, 1)
139139
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
140140
ZEND_END_ARG_INFO()
141141

@@ -443,7 +443,9 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DOMNamedNodeMap_g
443443
ZEND_ARG_TYPE_INFO(0, localName, IS_STRING, 0)
444444
ZEND_END_ARG_INFO()
445445

446-
#define arginfo_class_DOMNamedNodeMap_item arginfo_class_DOMNodeList_item
446+
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DOMNamedNodeMap_item, 0, 1, DOMNode, 1)
447+
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
448+
ZEND_END_ARG_INFO()
447449

448450
#define arginfo_class_DOMNamedNodeMap_count arginfo_class_DOMNode_getLineNo
449451

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
DOMXPath::query() can return DOMNodeList with DOMNameSpaceNode items
3+
--FILE--
4+
<?php
5+
6+
$xml = <<<'XML'
7+
<?xml version="1.0" encoding="UTF-8"?>
8+
<test></test>
9+
XML;
10+
$doc = new DomDocument;
11+
$doc->loadXML($xml);
12+
$xpath = new DOMXPath($doc);
13+
$nodes = $xpath->query('//namespace::*');
14+
var_dump($nodes->item(0));
15+
16+
?>
17+
--EXPECT--
18+
object(DOMNameSpaceNode)#3 (8) {
19+
["nodeName"]=>
20+
string(9) "xmlns:xml"
21+
["nodeValue"]=>
22+
string(36) "http://www.w3.org/XML/1998/namespace"
23+
["nodeType"]=>
24+
int(18)
25+
["prefix"]=>
26+
string(3) "xml"
27+
["localName"]=>
28+
string(3) "xml"
29+
["namespaceURI"]=>
30+
string(36) "http://www.w3.org/XML/1998/namespace"
31+
["ownerDocument"]=>
32+
string(22) "(object value omitted)"
33+
["parentNode"]=>
34+
string(22) "(object value omitted)"
35+
}

0 commit comments

Comments
 (0)