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'); 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')); foreach ($it as $k => $item) { print "K: ".$k." Item: ".$item->nodeName. " Value: ".$item->nodeValue. PHP_EOL; }
Output for 7.0.0 - 7.1.0
K: 0 Item: item Value: 1 K: 1 Item: item Value: 2 K: 2 Item: item Value: 3 ---- K: 3 Item: item Value: 1
Output for hhvm-3.10.0 - 3.12.0
K: 1 Item: item Value: 1 K: 2 Item: item Value: 2 K: 3 Item: item Value: 3 ---- K: 1 Item: item Value: 1 K: 2 Item: item Value: 2 K: 3 Item: item Value: 3
Output for 5.3.3 - 5.6.28
K: 0 Item: item Value: 1 K: 1 Item: item Value: 2 K: 2 Item: item Value: 3 ---- K: 2322280112866809376 Item: item Value: 1
Output for 5.2.0 - 5.3.2
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/sLdVL on line 19
Process exited with code 255.
Output for 5.1.0 - 5.1.1, 5.1.3 - 5.1.6
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/sLdVL on line 19
Process exited with code 255.
Output for 5.1.2
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/sLdVL on line 20
Process exited with code 255.
Output for 5.0.2 - 5.0.5
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/sLdVL on line 19
Process exited with code 255.
Output for 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLdVL on line 15 K: 0 Item: item Value: 1PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLdVL on line 15 K: 1 Item: item Value: 2PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLdVL on line 15 K: 2 Item: item Value: 3PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/sLdVL on line 18 ----PHP_EOL Fatal error: Class 'IteratorIterator' not found in /in/sLdVL on line 19
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/sLdVL on line 10
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: domdocument in /in/sLdVL 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/sLdVL on line 10