Doc #67806 [Nab]: DOMNodelist::item actually returns DOMElement

From: Date: Sat, 09 Aug 2014 01:31:43 +0000
Subject: Doc #67806 [Nab]: DOMNodelist::item actually returns DOMElement
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-11421@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67806&edit=1 ID: 67806 User updated by: danielklein at airpost dot net Reported by: danielklein at airpost dot net Summary: DOMNodelist::item actually returns DOMElement Status: Not a bug Type: Documentation Problem Package: Documentation problem PHP Version: 5.4.31 Block user comment: N Private report: N New Comment: OK, fair enough. Then the documentation should say that it returns mixed. Previous Comments: ------------------------------------------------------------------------ [2014-08-08 14:39:30] 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-08 12:40:54] 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? ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67806&edit=1

« previous php.doc.bugs (#11421) next »