xref: /PHP-5.6/ext/spl/tests/dllist_004.phpt (revision 0a6bcd44)
1--TEST--
2SPL: DoublyLinkedList: Stacks
3--FILE--
4<?php
5$stack = new SplStack();
6// errors
7try {
8    $stack->pop();
9} catch (RuntimeException $e) {
10    echo "Exception: ".$e->getMessage()."\n";
11}
12try {
13    $stack->shift();
14} catch (RuntimeException $e) {
15    echo "Exception: ".$e->getMessage()."\n";
16}
17
18// data consistency
19$a = 2;
20$stack->push($a);
21echo $stack->pop()."\n";
22
23// peakable
24$stack->push(1);
25$stack->push(2);
26echo $stack->top()."\n";
27
28// iterable
29foreach ($stack as $elem) {
30    echo "[$elem]\n";
31}
32
33// countable
34$stack->push(NULL);
35$stack->push(NULL);
36echo count($stack)."\n";
37echo $stack->count()."\n";
38var_dump($stack->pop());
39var_dump($stack->pop());
40
41// clonable
42$stack->push(2);
43$stack_clone = clone $stack;
44$stack_clone->pop();
45echo count($stack)."\n";
46?>
47===DONE===
48<?php exit(0); ?>
49--EXPECTF--
50Exception: Can't pop from an empty datastructure
51Exception: Can't shift from an empty datastructure
522
532
54[2]
55[1]
564
574
58NULL
59NULL
603
61===DONE===
62