xref: /PHP-5.3/ext/spl/tests/dllist_005.phpt (revision 3a4eb3e4)
1--TEST--
2SPL: DoublyLinkedList: Queues
3--INI--
4allow_call_time_pass_reference=1
5--FILE--
6<?php
7$queue = new SplQueue();
8// errors
9try {
10    $queue->dequeue();
11} catch (RuntimeException $e) {
12    echo "Exception: ".$e->getMessage()."\n";
13}
14try {
15    $queue->shift();
16} catch (RuntimeException $e) {
17    echo "Exception: ".$e->getMessage()."\n";
18}
19
20// data consistency
21$a = 2;
22$queue->enqueue($a);
23$a = 3;
24$queue->enqueue(&$a);
25$a = 4;
26echo $queue->dequeue()."\n";
27echo $queue->dequeue()."\n";
28
29// peakable
30$queue->enqueue(1);
31$queue->enqueue(2);
32echo $queue->top()."\n";
33
34// iterable
35foreach ($queue as $elem) {
36    echo "[$elem]\n";
37}
38
39// countable
40$queue->enqueue(NULL);
41$queue->enqueue(NULL);
42echo count($queue)."\n";
43echo $queue->count()."\n";
44var_dump($queue->dequeue());
45var_dump($queue->dequeue());
46
47// clonable
48$queue->enqueue(2);
49$queue_clone = clone $queue;
50$queue_clone->dequeue();
51echo count($queue)."\n";
52?>
53===DONE===
54<?php exit(0); ?>
55--EXPECTF--
56Exception: Can't shift from an empty datastructure
57Exception: Can't shift from an empty datastructure
582
593
602
61[1]
62[2]
634
644
65int(1)
66int(2)
673
68===DONE===
69