#42451 [Opn->Bgs]: get_class(DOMNodelist->item()) reports wrong class
| From: | rrichards@php.net | Date: | Tue, 28 Aug 2007 11:28:37 +0000 |
| Subject: | #42451 [Opn->Bgs]: get_class(DOMNodelist->item()) reports wrong class | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-116760@lists.php.net to get a copy of this message | ||
ID: 42451
Updated by: rrichards@php.net
Reported By: rkhb at gmx dot net
-Status: Open
+Status: Bogus
Bug Type: DOM XML related
Operating System: Windows XP Pro SP2
PHP Version: 5.2.4RC3
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2007-08-27 23:58:16] 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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42451&edit=1