ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilDclStack.php
Go to the documentation of this file.
1<?php
2
10{
11
15 protected $stack = array();
16
17
21 public function push($elem)
22 {
23 $this->stack[] = $elem;
24 }
25
26
30 public function pop()
31 {
32 if (!$this->isEmpty()) {
33 $last_index = count($this->stack) - 1;
34 $elem = $this->stack[$last_index];
35 unset($this->stack[$last_index]);
36 $this->stack = array_values($this->stack); // re-index
37
38 return $elem;
39 }
40
41 return null;
42 }
43
44
48 public function top()
49 {
50 if (!$this->isEmpty()) {
51 return $this->stack[count($this->stack) - 1];
52 }
53
54 return null;
55 }
56
57
61 public function isEmpty()
62 {
63 return !(bool) count($this->stack);
64 }
65
66
67 public function reset()
68 {
69 $this->stack = array();
70 }
71
72
76 public function count()
77 {
78 return count($this->stack);
79 }
80
81
82 public function debug()
83 {
84 echo "<pre>" . print_r($this->stack, 1) . "</pre>";
85 }
86}
An exception for terminatinating execution or to throw for unit testing.
Class ilDclStack.