[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] [php-src] master: Fix return value in stub file for DOMNodeList::item
From:       divinity76 via Niels Dossche <noreply () php ! net>
Date:       2023-05-29 17:15:30
Message-ID: fK7r1brjnKOjorRTDsOukLgueYvTaVtDyf8mI9Gfc () main ! php ! net
[Download RAW message or body]

Author: divinity76 (divinity76)
Committer: Niels Dossche (nielsdos)
Date: 2023-05-29T18:49:26+02:00

Commit: https://github.com/php/php-src/commit/761b9a44f8f097f77d0f96d479c485e9b11e51d6
Raw diff: https://github.com/php/php-src/commit/761b9a44f8f097f77d0f96d479c485e9b11e51d6.diff

Fix return value in stub file for DOMNodeList::item

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.

Changed paths:
  M  NEWS
  M  ext/dom/php_dom.stub.php
  M  ext/dom/php_dom_arginfo.h


Diff:

diff --git a/NEWS b/NEWS
index 40fb3e328b7d..143418e2a30d 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
diff --git a/ext/dom/php_dom.stub.php b/ext/dom/php_dom.stub.php
index f26518c0ba8e..45b54c21d6c2 100644
--- a/ext/dom/php_dom.stub.php
+++ b/ext/dom/php_dom.stub.php
@@ -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) {}
 }
 
diff --git a/ext/dom/php_dom_arginfo.h b/ext/dom/php_dom_arginfo.h
index 2ac8ae45f2b2..d63b43e9b95f 100644
--- a/ext/dom/php_dom_arginfo.h
+++ b/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)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic