php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42451 get_class(DOMNodelist->item()) reports wrong class
Submitted: 2007-08-27 23:58 UTC Modified: 2007-08-28 11:28 UTC
From: rkhb at gmx dot net Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.4RC3 OS: Windows XP Pro SP2
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: rkhb at gmx dot net
New email:
PHP Version: OS:

 

 [2007-08-27 23:58 UTC] rkhb at gmx dot net
Description:
------------
get_class(DOMNodelist->item()) reports 'DOMElement'. In the documentation as well as in the W3C-Recommendation this should be 'DOMNode'.

http://www.php.net/manual/en/function.dom-domnodelist-item.php
http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-536297177

I had required the correct result for building a own "print_r"...

Reproduce code:
---------------
error_reporting (E_ALL | E_STRICT);
echo "PHP: ", PHP_VERSION, "\r\n";
$doc = new DOMDocument;
$doc->loadHTML('<html><head><title>First</title><meta name="author" content="rkhb"></head><body></body></html>');

$heads = $doc->getElementsByTagName('head'); // -> DomNodeList
echo '$heads:  ' , get_class($heads),"\r\n";
$head = $heads->item(0); // -> DomNode
echo '$head:   ' , get_class($head),"\r\n";
$childs = $head->childNodes; // -> DomNodeList
echo '$childs: ',get_class($childs),"\r\n";
$child = $childs->item(0); // ->  DomNode;
echo '$child:  ',get_class($child),"\r\n";
echo '$child->nodeName: ',$child->nodeName,"\r\n";
echo '$child->tagName: ',$child->tagName,"\r\n";
echo '$child->undefined: ',$child->undefined,"\r\n";
echo '$child->nextSibling->nodeName: ',$child->nextSibling->nodeName,"\r\n";


Expected result:
----------------
HP: 5.2.4RC4-dev
$heads:  DOMNodeList
$head:   DOMNode
$childs: DOMNodeList
$child:  DOMNode
$child->nodeName: title
$child->tagName:
Notice: Undefined property:  DOMNode::$tagName in C:\Projekte\PHP-CLI\Neu1.php on line 25
$child->undefined: 
Notice: Undefined property:  DOMNode::$undefined in C:\Projekte\PHP-CLI\Neu1.php on line 25

$child->nextSibling->nodeName: meta

Actual result:
--------------
HP: 5.2.4RC4-dev
$heads:  DOMNodeList
$head:   DOMElement
$childs: DOMNodeList
$child:  DOMElement
$child->nodeName: title
$child->tagName: title
$child->undefined: 
Notice: Undefined property:  DOMElement::$undefined in C:\Projekte\PHP-CLI\Neu1.php on line 25

$child->nextSibling->nodeName: meta

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-28 11:28 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Returned object just need to inherit from DOMNode, so the actual class type of the objects returned can be a number of different class types (DOMElement, DOMAttr, DOMText, etc...)

You can test for DOMNode using instanceof.
$child instanceof DOMNode
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 05 12:01:29 2025 UTC