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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC