3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Q extends SplQueue { } $q = new Q(); $q->enqueue('first'); $q->enqueue('second'); $q->enqueue('third'); foreach($q as $index => $value){ echo $index . " , " . $value . PHP_EOL; } var_dump($q); $out = $q->dequeue(); var_dump($q); $q->enqueue($out); var_dump($q); foreach($q as $index => $value){ echo $index . " , " . $value . PHP_EOL; } echo "===================================" . PHP_EOL; class PQ extends SplPriorityQueue{} $pq = new PQ(); $pq->insert('first', 1); $pq->insert('fifth', 5); $pq->insert('third', 3); foreach($pq as $pr => $val){ echo $pr . " - " . $val . PHP_EOL; } echo PHP_EOL; echo $pq->next();
based on rlAol
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.3.0rc3
0 , first 1 , second 2 , third object(Q)#1 (2) { ["flags":"SplDoublyLinkedList":private]=> int(4) ["dllist":"SplDoublyLinkedList":private]=> array(3) { [0]=> string(5) "first" [1]=> string(6) "second" [2]=> string(5) "third" } } object(Q)#1 (2) { ["flags":"SplDoublyLinkedList":private]=> int(4) ["dllist":"SplDoublyLinkedList":private]=> array(2) { [0]=> string(6) "second" [1]=> string(5) "third" } } object(Q)#1 (2) { ["flags":"SplDoublyLinkedList":private]=> int(4) ["dllist":"SplDoublyLinkedList":private]=> array(3) { [0]=> string(6) "second" [1]=> string(5) "third" [2]=> string(5) "first" } } 0 , second 1 , third 2 , first =================================== 2 - fifth 1 - third 0 - first
Output for hhvm-3.18.5 - 3.22.0
0 , first 1 , second 2 , third object(Q)#1 (6) { ["head":protected]=> object(_SplDoublyLinkedListNode)#2 (3) { ["data"]=> string(5) "first" ["next"]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> string(6) "second" ["next"]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> string(5) "third" ["next"]=> NULL ["prev"]=> *RECURSION* } ["prev"]=> *RECURSION* } ["prev"]=> NULL } ["tail":protected]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> string(5) "third" ["next"]=> NULL ["prev"]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> string(6) "second" ["next"]=> *RECURSION* ["prev"]=> object(_SplDoublyLinkedListNode)#2 (3) { ["data"]=> string(5) "first" ["next"]=> *RECURSION* ["prev"]=> NULL } } } ["key":protected]=> int(3) ["current":protected]=> NULL ["count":protected]=> int(3) ["mode":protected]=> int(0) } object(Q)#1 (6) { ["head":protected]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> string(6) "second" ["next"]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> string(5) "third" ["next"]=> NULL ["prev"]=> *RECURSION* } ["prev"]=> NULL } ["tail":protected]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> string(5) "third" ["next"]=> NULL ["prev"]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> string(6) "second" ["next"]=> *RECURSION* ["prev"]=> NULL } } ["key":protected]=> int(3) ["current":protected]=> NULL ["count":protected]=> int(2) ["mode":protected]=> int(0) } object(Q)#1 (6) { ["head":protected]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> string(6) "second" ["next"]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> string(5) "third" ["next"]=> object(_SplDoublyLinkedListNode)#5 (3) { ["data"]=> string(5) "first" ["next"]=> NULL ["prev"]=> *RECURSION* } ["prev"]=> *RECURSION* } ["prev"]=> NULL } ["tail":protected]=> object(_SplDoublyLinkedListNode)#5 (3) { ["data"]=> string(5) "first" ["next"]=> NULL ["prev"]=> object(_SplDoublyLinkedListNode)#4 (3) { ["data"]=> string(5) "third" ["next"]=> *RECURSION* ["prev"]=> object(_SplDoublyLinkedListNode)#3 (3) { ["data"]=> string(6) "second" ["next"]=> *RECURSION* ["prev"]=> NULL } } } ["key":protected]=> int(3) ["current":protected]=> NULL ["count":protected]=> int(3) ["mode":protected]=> int(0) } 0 , second 1 , third 2 , first =================================== 2 - fifth 1 - third 0 - first