3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $doubly=new SplDoublyLinkedList(); $doubly->push(array('name'=>'Naruto')); $doubly->push(array('name'=>'Sakura')); $doubly->push(array('name'=>'Neji')); $doubly->push(array('name'=>'Sasuke')); var_dump($doubly); echo "\r\n FIFO Traversing \r\n"; $doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO | SplDoublyLinkedList::IT_MODE_KEEP); $doubly->rewind(); foreach($doubly as $key=>$value) { echo "\r\nTraversed:".$key.' '.$value['name']; } echo "\r\nLIFO Traversing - Keep mode \r\n"; $doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_KEEP); $doubly->rewind(); foreach($doubly as $key=>$value) { echo "\r\nTraversed:".$key.' '.$value['name']; } echo "\r\nLIFO Traversing - Delete mode \r\n"; $doubly->setIteratorMode(SplDoublyLinkedList::IT_MODE_LIFO | SplDoublyLinkedList::IT_MODE_DELETE); $doubly->rewind(); foreach($doubly as $key=>$value) { if($key == 2) break; echo "\r\nTraversed:".$key.' '.$value['name']; } var_dump($doubly);
based on fYEHe
Output for 5.3.0 - 5.6.21, 7.0.0 - 7.1.0
object(SplDoublyLinkedList)#1 (2) { ["flags":"SplDoublyLinkedList":private]=> int(0) ["dllist":"SplDoublyLinkedList":private]=> array(4) { [0]=> array(1) { ["name"]=> string(6) "Naruto" } [1]=> array(1) { ["name"]=> string(6) "Sakura" } [2]=> array(1) { ["name"]=> string(4) "Neji" } [3]=> array(1) { ["name"]=> string(6) "Sasuke" } } } FIFO Traversing Traversed:0 Naruto Traversed:1 Sakura Traversed:2 Neji Traversed:3 Sasuke LIFO Traversing - Keep mode Traversed:3 Sasuke Traversed:2 Neji Traversed:1 Sakura Traversed:0 Naruto LIFO Traversing - Delete mode Traversed:3 Sasukeobject(SplDoublyLinkedList)#1 (2) { ["flags":"SplDoublyLinkedList":private]=> int(3) ["dllist":"SplDoublyLinkedList":private]=> array(3) { [0]=> array(1) { ["name"]=> string(6) "Naruto" } [1]=> array(1) { ["name"]=> string(6) "Sakura" } [2]=> array(1) { ["name"]=> string(4) "Neji" } } }
Output for hhvm-3.12.0
object(SplDoublyLinkedList)#1 (6) { ["head":protected]=> object(_SplDoublyLinkedListNode)#2 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Naruto" } ["next"]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Sakura" } ["next"]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> array(1) { ["name"]=> string(4) "Neji" } ["next"]=> object(_SplDoublyLinkedListNode)#5 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Sasuke" } ["next"]=> NULL ["prev"]=> *RECURSION* } ["prev"]=> *RECURSION* } ["prev"]=> *RECURSION* } ["prev"]=> NULL } ["tail":protected]=> object(_SplDoublyLinkedListNode)#5 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Sasuke" } ["next"]=> NULL ["prev"]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> array(1) { ["name"]=> string(4) "Neji" } ["next"]=> *RECURSION* ["prev"]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Sakura" } ["next"]=> *RECURSION* ["prev"]=> object(_SplDoublyLinkedListNode)#2 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Naruto" } ["next"]=> *RECURSION* ["prev"]=> NULL } } } } ["key":protected]=> int(0) ["current":protected]=> NULL ["count":protected]=> int(4) ["mode":protected]=> int(0) } FIFO Traversing Traversed:0 Naruto Traversed:1 Sakura Traversed:2 Neji Traversed:3 Sasuke LIFO Traversing - Keep mode Traversed:3 Sasuke Traversed:2 Neji Traversed:1 Sakura Traversed:0 Naruto LIFO Traversing - Delete mode Traversed:3 Sasukeobject(SplDoublyLinkedList)#1 (6) { ["head":protected]=> object(_SplDoublyLinkedListNode)#2 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Naruto" } ["next"]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Sakura" } ["next"]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> array(1) { ["name"]=> string(4) "Neji" } ["next"]=> NULL ["prev"]=> *RECURSION* } ["prev"]=> *RECURSION* } ["prev"]=> NULL } ["tail":protected]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> array(1) { ["name"]=> string(4) "Neji" } ["next"]=> NULL ["prev"]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Sakura" } ["next"]=> *RECURSION* ["prev"]=> object(_SplDoublyLinkedListNode)#2 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Naruto" } ["next"]=> *RECURSION* ["prev"]=> NULL } } } ["key":protected]=> int(2) ["current":protected]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> array(1) { ["name"]=> string(4) "Neji" } ["next"]=> NULL ["prev"]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Sakura" } ["next"]=> *RECURSION* ["prev"]=> object(_SplDoublyLinkedListNode)#2 (3) { ["data"]=> array(1) { ["name"]=> string(6) "Naruto" } ["next"]=> *RECURSION* ["prev"]=> NULL } } } ["count":protected]=> int(3) ["mode":protected]=> int(3) }
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.0.0 - 5.2.17
Fatal error: Class 'SplDoublyLinkedList' not found in /in/pPMKV on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected '|', expecting '(' in /in/pPMKV on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '|', expecting '(' in /in/pPMKV on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'('' in /in/pPMKV on line 10
Process exited with code 255.