Skip to content

Commit

Permalink
Fix return type of DOMNodeList::item()
Browse files Browse the repository at this point in the history
It can also return DOMNameSpaceNode :(
  • Loading branch information
nikic committed Jul 21, 2021
1 parent 21d9931 commit 1602db2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
4 changes: 2 additions & 2 deletions ext/dom/php_dom.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ public function count(): int {}

public function getIterator(): Iterator {}

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

class DOMCharacterData extends DOMNode implements DOMChildNode
Expand Down
8 changes: 5 additions & 3 deletions ext/dom/php_dom_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 9085cafc2477ac2efa9929a681251bf0f2f39879 */
* Stub hash: 2931a77f1b3b92494ce05cf44c2175dfae5f777f */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 1)
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
Expand Down Expand Up @@ -135,7 +135,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_DOMNodeList_getIterator, 0, 0, Iterator, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DOMNodeList_item, 0, 1, DOMNode, 1)
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_DOMNodeList_item, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
ZEND_END_ARG_INFO()

Expand Down Expand Up @@ -443,7 +443,9 @@ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DOMNamedNodeMap_g
ZEND_ARG_TYPE_INFO(0, localName, IS_STRING, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_DOMNamedNodeMap_item arginfo_class_DOMNodeList_item
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_DOMNamedNodeMap_item, 0, 1, DOMNode, 1)
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
ZEND_END_ARG_INFO()

#define arginfo_class_DOMNamedNodeMap_count arginfo_class_DOMNode_getLineNo

Expand Down
35 changes: 35 additions & 0 deletions ext/dom/tests/xpath_domnamespacenode.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
DOMXPath::query() can return DOMNodeList with DOMNameSpaceNode items
--FILE--
<?php

$xml = <<<'XML'
<?xml version="1.0" encoding="UTF-8"?>
<test></test>
XML;
$doc = new DomDocument;
$doc->loadXML($xml);
$xpath = new DOMXPath($doc);
$nodes = $xpath->query('//namespace::*');
var_dump($nodes->item(0));

?>
--EXPECT--
object(DOMNameSpaceNode)#3 (8) {
["nodeName"]=>
string(9) "xmlns:xml"
["nodeValue"]=>
string(36) "http://www.w3.org/XML/1998/namespace"
["nodeType"]=>
int(18)
["prefix"]=>
string(3) "xml"
["localName"]=>
string(3) "xml"
["namespaceURI"]=>
string(36) "http://www.w3.org/XML/1998/namespace"
["ownerDocument"]=>
string(22) "(object value omitted)"
["parentNode"]=>
string(22) "(object value omitted)"
}

0 comments on commit 1602db2

Please sign in to comment.