1 | <?php |
||
9 | trait ContainerArrayAccessTrait |
||
10 | { |
||
11 | /** |
||
12 | * Determine if a given offset exists. |
||
13 | * |
||
14 | * @param string $key |
||
15 | * @return bool |
||
16 | */ |
||
17 | public function offsetExists($key) |
||
21 | |||
22 | /** |
||
23 | * Get the value at a given offset. |
||
24 | * |
||
25 | * @param string $key |
||
26 | * @return mixed |
||
27 | */ |
||
28 | public function offsetGet($key) |
||
32 | |||
33 | /** |
||
34 | * Set the value at a given offset. |
||
35 | * |
||
36 | * @param string $key |
||
37 | * @param mixed $value |
||
38 | * @return void |
||
39 | */ |
||
40 | public function offsetSet($key, $value) |
||
44 | |||
45 | /** |
||
46 | * Unset the value at a given offset. |
||
47 | * |
||
48 | * @param string $key |
||
49 | * @return void |
||
50 | */ |
||
51 | public function offsetUnset($key) |
||
55 | |||
56 | /** |
||
57 | * Dynamically access container services. |
||
58 | * |
||
59 | * @param string $key |
||
60 | * @return mixed |
||
61 | */ |
||
62 | public function __get($key) |
||
66 | |||
67 | /** |
||
68 | * Dynamically set container services. |
||
69 | * |
||
70 | * @param string $key |
||
71 | * @param mixed $value |
||
72 | * @return void |
||
73 | */ |
||
74 | public function __set($key, $value) |
||
78 | } |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.