1 | <?php |
||
28 | trait ArrayAccessTrait |
||
29 | { |
||
30 | /** |
||
31 | * Check whether or not a specific offset exists. |
||
32 | * |
||
33 | * @aliasof exists |
||
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 offsetExists($offset) |
||
42 | |||
43 | /** |
||
44 | * Get the value for a specific offset. |
||
45 | * |
||
46 | * @aliasof get |
||
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 offsetGet($offset) |
||
58 | |||
59 | /** |
||
60 | * Set the value for a specific offset. |
||
61 | * |
||
62 | * @aliasof set |
||
63 | * @param integer $offset The location in the collection to set a new value for. |
||
64 | * @param mixed $value The new value for the collection location. |
||
65 | */ |
||
66 | public function offsetSet($offset, $value) |
||
73 | |||
74 | /** |
||
75 | * Unset the value for a specific offset. |
||
76 | * |
||
77 | * @aliasof remove |
||
78 | * @param integer $offset The location in the collection to unset. |
||
79 | */ |
||
80 | public function offsetUnset($offset) |
||
87 | } |
||
88 |
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: