php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #67806 DOMNodelist::item actually returns DOMElement
Submitted: 2014-08-08 12:40 UTC Modified: 2014-08-09 01:31 UTC
From: danielklein at airpost dot net Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 5.4.31 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: danielklein at airpost dot net
New email:
PHP Version: OS:

 

 [2014-08-08 12:40 UTC] danielklein at airpost dot net
Description:
------------
DOMNodelist::item actually returns DOMElement, not DOMNode as stated in the documentation. Since DOMElement extends DOMNode, this is not a huge problem in that all the methods and properties will work as documented but the programmer is potentially missing out on a lot of useful features.

Bug #42451 is also about this issue (but the reverse, asking for PHP to match the documentation). Perhaps a note in DOMNodelist::item explaining that as DOMElement extends DOMNode that it is actually correct?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-08 14:39 UTC] salathe@php.net
-Status: Open +Status: Not a bug
 [2014-08-08 14:39 UTC] salathe@php.net
DOMNodeList::item() can return DOMElement but can also return other things that are DOMNodes, such as DOMText, DOMAttr.

The example:

<?php

$doc = new DOMDocument;
$doc->loadXML('<example a="Apple">Example</example>');

$xpath = new DOMXPath($doc);
$nodelist = $xpath->query('/example/@*|/example/text()');

var_dump(
  get_class($nodelist),
  get_class($nodelist->item(0)),
  get_class($nodelist->item(1))
);

?>

Outputs:

string(11) "DOMNodeList"
string(7) "DOMAttr"
string(7) "DOMText"
 [2014-08-09 01:31 UTC] danielklein at airpost dot net
OK, fair enough. Then the documentation should say that it returns mixed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 11:01:34 2025 UTC