Using PHP array functions on a DOMDocument NodeList

The PHP DOMDocument class implements the W3C DOM. However, PHP implementation is quite different from its JavaScript counterpart, so it's not so easy to make something like this:

$dom = new DOMDocument();
$dom->load('test.xml');

$items = $dom->getElementsByTagName('item');
$items = array_slice($items, 0, 3); // returns an error

The fact is that we're actually dealing with a NodeList collection of DOM element objects, so it's not possible to use array functions on them (with JavaScript there are a couple of tricks to perform this operation, though). I have to test more extensively this feature to solve this problem. So far I've played a little bit with PHP iterators, but I wasn't lucky, perhaps because I'm using a wrong approach. I'll let you know, so stay tuned.