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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 13:01:30 2024 UTC