3v4l.org

run code in 300+ PHP versions simultaneously
<?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($items); foreach ($it as $k => $item) { print "K: ".$k." Item: ".$item->nodeName. " Value: ".$item->nodeValue. PHP_EOL; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
K: 0 Item: item Value: 1 K: 1 Item: item Value: 2 K: 2 Item: item Value: 3 ---- K: 0 Item: item Value: 1 K: 1 Item: item Value: 2 K: 2 Item: item Value: 3
Output for 7.0.0 - 7.0.31, 7.1.0 - 7.1.21, 7.2.0 - 7.2.33, 7.3.12 - 7.3.33, 7.4.0 - 7.4.33
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 5.3.3 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.30
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.2.17, 5.3.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/IGWHd on line 20
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/IGWHd on line 20
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/IGWHd on line 21
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/IGWHd on line 20
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/IGWHd on line 16 K: 0 Item: item Value: 1PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/IGWHd on line 16 K: 1 Item: item Value: 2PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/IGWHd on line 16 K: 2 Item: item Value: 3PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/IGWHd on line 19 ----PHP_EOL Fatal error: Class 'IteratorIterator' not found in /in/IGWHd on line 20
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.1, 4.4.3 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/IGWHd on line 11
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: domdocument in /in/IGWHd on line 12
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/IGWHd on line 11

preferences:
295.77 ms | 401 KiB | 401 Q