summaryrefslogtreecommitdiff
path: root/ext/spl/tests/dllist_004.phpt
blob: 44d9611fca0bf66b126cd8546006259acb4d431d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
--TEST--
SPL: DoublyLinkedList: Stacks
--FILE--
<?php
$stack = new SplStack();
// errors
try {
    $stack->pop();
} catch (RuntimeException $e) {
    echo "Exception: ".$e->getMessage()."\n";
}
try {
    $stack->shift();
} catch (RuntimeException $e) {
    echo "Exception: ".$e->getMessage()."\n";
}

// data consistency
$a = 2;
$stack->push($a);
echo $stack->pop()."\n";

// peakable
$stack->push(1);
$stack->push(2);
echo $stack->top()."\n";

// iterable
foreach ($stack as $elem) {
    echo "[$elem]\n";
}

// countable
$stack->push(NULL);
$stack->push(NULL);
echo count($stack)."\n";
echo $stack->count()."\n";
var_dump($stack->pop());
var_dump($stack->pop());

// clonable
$stack->push(2);
$stack_clone = clone $stack;
$stack_clone->pop();
echo count($stack)."\n";
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
Exception: Can't pop from an empty datastructure
Exception: Can't shift from an empty datastructure
2
2
[2]
[1]
4
4
NULL
NULL
3
===DONE===