1 | <?php |
||
7 | class ArrayList implements ListInterface { |
||
8 | private $data; |
||
9 | private $current; |
||
10 | private $position; |
||
11 | private $size; |
||
12 | |||
13 | public function __construct() { |
||
17 | |||
18 | public function insert($index, $data) { |
||
21 | |||
22 | public function clear() { |
||
25 | |||
26 | public function get($index) { |
||
29 | |||
30 | public function getAll() { |
||
33 | |||
34 | public function empty() : bool { |
||
37 | |||
38 | public function delete($index) { |
||
41 | |||
42 | public function size() : int { |
||
45 | |||
46 | public function toArray() : array { |
||
49 | |||
50 | /** |
||
51 | * Reset the cursor position. |
||
52 | */ |
||
53 | public function rewind() { |
||
57 | |||
58 | /** |
||
59 | * Returns the current node data. |
||
60 | * |
||
61 | * @return mixed |
||
62 | */ |
||
63 | public function current() { |
||
66 | |||
67 | /** |
||
68 | * Key or index that indicates the cursor position. |
||
69 | * |
||
70 | * @return integer The current position. |
||
71 | */ |
||
72 | public function key() { |
||
75 | |||
76 | /** |
||
77 | * Move the cursor to the next node and increments the |
||
78 | * position counter. |
||
79 | */ |
||
80 | public function next() { |
||
84 | |||
85 | /** |
||
86 | * Returns if the current pointer position is valid. |
||
87 | * |
||
88 | * @return boolean true if pointer is not last, else false. |
||
89 | */ |
||
90 | public function valid() { |
||
93 | |||
94 | /** |
||
95 | * Binds to count() method. This is equal to make $this->list->size(). |
||
96 | * |
||
97 | * @return integer the list size. 0 if it is empty. |
||
98 | */ |
||
99 | public function count() { |
||
102 | |||
103 | public function offsetSet($offset, $valor) { |
||
111 | |||
112 | public function offsetExists($offset) { |
||
117 | |||
118 | public function offsetUnset($offset) { |
||
122 | |||
123 | public function offsetGet($offset) { |
||
128 | } |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: