3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $XML = <<< XML <root> <item>1</item> <item>2</item> <item>3</item> </root> XML; $dom = new DomDocument(); $dom->loadXml($XML); $items = $dom->getElementsByTagName('item'); echo "Count: {$items->length}", PHP_EOL; foreach ($items as $k => $item) { print "K: ".$k." Item: ".$item->nodeName. " Value: ".$item->nodeValue. PHP_EOL; } print "----" . PHP_EOL; $it = new IteratorIterator($dom->getElementsByTagName('item')); $c = iterator_count($it); echo "Count: $c", PHP_EOL; foreach ($it as $k => $item) { print "K: ".$k." Item: ".$item->nodeName. " Value: ".$item->nodeValue. PHP_EOL; }
Output for 5.3.3 - 5.6.28, 7.0.0 - 7.1.0
Count: 3 K: 0 Item: item Value: 1 K: 1 Item: item Value: 2 K: 2 Item: item Value: 3 ---- Count: 1
Output for hhvm-3.12.0
Count: 3 K: 1 Item: item Value: 1 K: 2 Item: item Value: 2 K: 3 Item: item Value: 3 ---- Count: 3 K: 1 Item: item Value: 1 K: 2 Item: item Value: 2 K: 3 Item: item Value: 3
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.2.0 - 5.3.2
Count: 3 K: 0 Item: item Value: 1 K: 1 Item: item Value: 2 K: 2 Item: item Value: 3 ---- Catchable fatal error: Argument 1 passed to IteratorIterator::__construct() must implement interface Traversable, instance of DOMNodeList given in /in/LtSmU on line 20
Process exited with code 255.
Output for 5.1.0 - 5.1.1, 5.1.3 - 5.1.6
Count: 3 K: 0 Item: item Value: 1 K: 1 Item: item Value: 2 K: 2 Item: item Value: 3 ---- Fatal error: Argument 1 passed to IteratorIterator::__construct() must implement interface Traversable in /in/LtSmU on line 20
Process exited with code 255.
Output for 5.1.2
Count: 3 K: 0 Item: item Value: 1 K: 1 Item: item Value: 2 K: 2 Item: item Value: 3 ---- Fatal error: Argument 1 passed to IteratorIterator::__construct() must implement interface Traversable in /in/LtSmU on line 21
Process exited with code 255.
Output for 5.0.2 - 5.0.5
Count: 3 K: 0 Item: item Value: 1 K: 1 Item: item Value: 2 K: 2 Item: item Value: 3 ---- Fatal error: Class 'IteratorIterator' not found in /in/LtSmU on line 20
Process exited with code 255.
Output for 5.0.0 - 5.0.1
Count: 3 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LtSmU on line 14 PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LtSmU on line 16 K: 0 Item: item Value: 1PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LtSmU on line 16 K: 1 Item: item Value: 2PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LtSmU on line 16 K: 2 Item: item Value: 3PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/LtSmU on line 19 ----PHP_EOL Fatal error: Class 'IteratorIterator' not found in /in/LtSmU on line 20
Process exited with code 255.
Output for 4.3.2 - 4.4.1, 4.4.3 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/LtSmU on line 10
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: domdocument in /in/LtSmU on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/LtSmU on line 10