1 | <?php |
||
5 | trait FluentArrayAccess |
||
6 | { |
||
7 | /** |
||
8 | * Get an attribute from the container. |
||
9 | * |
||
10 | * @param string $key |
||
11 | * @param mixed $default |
||
12 | * @return mixed |
||
13 | */ |
||
14 | abstract public function get($key, $default = null); |
||
15 | |||
16 | /** |
||
17 | * Determine if the given offset exists. |
||
18 | * |
||
19 | * @param string $offset |
||
20 | * @return bool |
||
21 | */ |
||
22 | public function offsetExists($offset) |
||
26 | |||
27 | /** |
||
28 | * Get the value for a given offset. |
||
29 | * |
||
30 | * @param string $offset |
||
31 | * @return mixed |
||
32 | */ |
||
33 | public function offsetGet($offset) |
||
37 | |||
38 | /** |
||
39 | * Set the value at the given offset. |
||
40 | * |
||
41 | * @param string $offset |
||
42 | * @param mixed $value |
||
43 | * @return void |
||
44 | */ |
||
45 | public function offsetSet($offset, $value) |
||
49 | |||
50 | /** |
||
51 | * Unset the value at the given offset. |
||
52 | * |
||
53 | * @param string $offset |
||
54 | * @return void |
||
55 | */ |
||
56 | public function offsetUnset($offset) |
||
60 | } |
||
61 |
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: