1 | <?php |
||
28 | trait AliasTrait |
||
29 | { |
||
30 | /** |
||
31 | * Check whether or not a specific offset exists. |
||
32 | * |
||
33 | * @see ArrayIterator::offsetExists |
||
34 | * @param integer $offset The location in the collection to verify the existence of. |
||
35 | * @return boolean A value of `true` indicates that the collection offset exists. A value of `false` |
||
36 | * indicates that it does not. |
||
37 | */ |
||
38 | public function exists($offset) |
||
42 | |||
43 | /** |
||
44 | * Get the value for a specific offset. |
||
45 | * |
||
46 | * @see ArrayIterator::offsetGet |
||
47 | * @param integer $offset The location in the collection to retrieve the value for. |
||
48 | * @return mixed The value of the collection offset. `NULL` is returned if the offset does not exist. |
||
49 | */ |
||
50 | public function get($offset) |
||
58 | |||
59 | /** |
||
60 | * Set the value for a specific offset. |
||
61 | * |
||
62 | * @see ArrayIterator::offsetSet |
||
63 | * @param integer $offset The location in the collection to set a new value for. |
||
64 | * @param integer $value The new value for the collection location. |
||
65 | */ |
||
66 | public function set($offset, $value) |
||
72 | |||
73 | /** |
||
74 | * Unset the value for a specific offset. |
||
75 | * |
||
76 | * @see ArrayIterator::offsetUnset |
||
77 | * @param integer $offset The location in the collection to unset. |
||
78 | */ |
||
79 | public function remove($offset) |
||
87 | |||
88 | /** |
||
89 | * Count the number of elements in a collection. |
||
90 | * |
||
91 | * @aliasof count |
||
92 | * @return integer The number of elements in a collection. |
||
93 | */ |
||
94 | public function length() |
||
98 | |||
99 | /** |
||
100 | * Count the number of elements in a collection. |
||
101 | * |
||
102 | * @aliasof set |
||
103 | * @return integer The number of elements in a collection. |
||
104 | */ |
||
105 | public function size() |
||
109 | } |
||
110 |
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: