#38489 [Com]: DOMNodeList should implement Traversable

From: Date: Wed, 17 Jan 2007 15:09:11 +0000
Subject: #38489 [Com]: DOMNodeList should implement Traversable
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-107685@lists.php.net to get a copy of this message
ID: 38489 Comment by: jules_papillon_fh at yahoo dot de Reported By: mmcintyre at squiz dot net Status: Open Bug Type: Feature/Change Request Operating System: * PHP Version: 5.1.5 New Comment: Another Code to reproduce the Bug: ---------------------------------- $dom = new DOMDocument('1.0', 'ISO-8859-1'); $dom->load('file.xml'); $iterator = new RecursiveIteratorIterator($dom->childNodes, RecursiveIteratorIterator::SELF_FIRST); foreach($iterator as $name => $element) { print $name . "\n"; } Expected result: ---------------- A recursive List of all Elements Actual result: -------------- "Catchable fatal error: Argument 1 passed to RecursiveIteratorIterator::__construct() must implement interface Traversable, instance of DOMNodeList given, called in […] and defined in […]" Previous Comments: ------------------------------------------------------------------------ [2006-08-18 06:37:22] mmcintyre at squiz dot net Description: ------------ Currently, a DOMNodeList object can be traversed using a foreach loop, but it cannot be converted to an array using iterator_to_array(), as it produces an error "Warning: iterator_to_array() expects parameter 1 to be Traversable, object given" Reproduce code: --------------- $xml = '<queries><query attr1="value"></query></queries>'; $doc = new DOMDocument; $doc->loadXML($xml); $queries = $doc->getElementsByTagName('queries'); $nodes = iterator_to_array($queries); Expected result: ---------------- The nodes in the NodeList are returned as an array. Actual result: -------------- "Warning: iterator_to_array() expects parameter 1 to be Traversable, object given" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38489&edit=1

« previous php.bugs (#107685) next »