3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /* * Examples of DoublyLinkedList */ $obj = new SplDoublyLinkedList(); // Check wither linked list is empty if ($obj->isEmpty()) { echo "Adding nodes to Linked List<br>"; $obj->push(2); $obj->push(3); echo "Adding the node at beginning of doubly linked list <br>"; $obj->unshift(10); } echo "<br>Our Linked List:"; print_r($obj); $curr = $obj->current(); // this will return NULL as we have not set initial node. echo "<br> Rewinding the position so that current node points to first node "; $obj->rewind(); echo "<br>Current node of the linked list:"; echo $obj->current(); // this will print first node of the linked list. echo "<br>Moving to Next node:"; $obj->next(); echo "<br>Printing the next node:"; echo $obj->current();
based on nNFMp
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Adding nodes to Linked List<br>Adding the node at beginning of doubly linked list <br><br>Our Linked List:SplDoublyLinkedList Object ( [flags:SplDoublyLinkedList:private] => 0 [dllist:SplDoublyLinkedList:private] => Array ( [0] => 10 [1] => 2 [2] => 3 ) ) <br> Rewinding the position so that current node points to first node <br>Current node of the linked list:10<br>Moving to Next node:<br>Printing the next node:2
Output for hhvm-3.10.0 - 3.12.0
Adding nodes to Linked List<br>Adding the node at beginning of doubly linked list <br><br>Our Linked List:SplDoublyLinkedList Object ( [head:protected] => _SplDoublyLinkedListNode Object ( [data] => 10 [next] => _SplDoublyLinkedListNode Object ( [data] => 2 [next] => _SplDoublyLinkedListNode Object ( [data] => 3 [next] => [prev] => _SplDoublyLinkedListNode Object ( [data] => 2 [next] => _SplDoublyLinkedListNode Object ( [data] => 3 [next] => [prev] => Array *RECURSION* ) [prev] => _SplDoublyLinkedListNode Object ( [data] => 10 [next] => Array *RECURSION* [prev] => ) ) ) [prev] => _SplDoublyLinkedListNode Object ( [data] => 10 [next] => _SplDoublyLinkedListNode Object ( [data] => 2 [next] => _SplDoublyLinkedListNode Object ( [data] => 3 [next] => [prev] => Array *RECURSION* ) [prev] => Array *RECURSION* ) [prev] => ) ) [prev] => ) [tail:protected] => _SplDoublyLinkedListNode Object ( [data] => 3 [next] => [prev] => _SplDoublyLinkedListNode Object ( [data] => 2 [next] => _SplDoublyLinkedListNode Object ( [data] => 3 [next] => [prev] => _SplDoublyLinkedListNode Object ( [data] => 2 [next] => Array *RECURSION* [prev] => _SplDoublyLinkedListNode Object ( [data] => 10 [next] => Array *RECURSION* [prev] => ) ) ) [prev] => _SplDoublyLinkedListNode Object ( [data] => 10 [next] => _SplDoublyLinkedListNode Object ( [data] => 2 [next] => _SplDoublyLinkedListNode Object ( [data] => 3 [next] => [prev] => Array *RECURSION* ) [prev] => _SplDoublyLinkedListNode Object ( [data] => 10 [next] => Array *RECURSION* [prev] => ) ) [prev] => ) ) ) [key:protected] => 0 [current:protected] => [count:protected] => 3 [mode:protected] => 0 ) <br> Rewinding the position so that current node points to first node <br>Current node of the linked list:10<br>Moving to Next node:<br>Printing the next node:2
Output for 5.0.0 - 5.2.17
Fatal error: Class 'SplDoublyLinkedList' not found in /in/1d5RW on line 6
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: spldoublylinkedlist in /in/1d5RW on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: spldoublylinkedlist in /in/1d5RW on line 6