Skip to content

Commit

Permalink
Fix return value in stub file for DOMNodeList::item
Browse files Browse the repository at this point in the history
Not explicitly documenting the possibility of returning DOMElement causes
the Intelephense linter (a popular PHP linter with ~9 million downloads:
https://marketplace.visualstudio.com/items?itemName=bmewburn.vscode-intelephense-client)
to think this code is bad:

  $xp->query("whatever")->item(0)->getAttribute("foo");

DOMNode does not have getAttribute (while DOMElement does).
Documenting the DOMElement return type should fix Intelephense's linter.

Closes GH-11342.
  • Loading branch information
divinity76 authored and nielsdos committed May 29, 2023
1 parent c473787 commit 761b9a4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -10,6 +10,7 @@ PHP NEWS
and segfaults with replaceWith). (nielsdos)
. Fixed bug GH-10234 (Setting DOMAttr::textContent results in an empty
attribute value). (nielsdos)
. Fix return value in stub file for DOMNodeList::item. (divinity76)

- Opcache:
. Fix allocation loop in zend_shared_alloc_startup(). (nielsdos)
Expand Down
2 changes: 1 addition & 1 deletion ext/dom/php_dom.stub.php
Expand Up @@ -232,7 +232,7 @@ public function count(): int {}

public function getIterator(): Iterator {}

/** @return DOMNode|DOMNameSpaceNode|null */
/** @return DOMElement|DOMNode|DOMNameSpaceNode|null */
public function item(int $index) {}
}

Expand Down
2 changes: 1 addition & 1 deletion ext/dom/php_dom_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 74698bea9c5e0635cf91345e8512b9677489510c */
* Stub hash: a62e383b05df81ea245a7993215fb8ff4e1c7f9d */

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_dom_import_simplexml, 0, 1, DOMElement, 0)
ZEND_ARG_TYPE_INFO(0, node, IS_OBJECT, 0)
Expand Down

0 comments on commit 761b9a4

Please sign in to comment.