1 | <?php |
||
9 | trait ArrayAccessTrait |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * Determine if the given configuration option exists. |
||
14 | * |
||
15 | * @param string $key |
||
16 | * @return bool |
||
17 | */ |
||
18 | public function offsetExists($key) |
||
22 | |||
23 | /** |
||
24 | * Get a configuration option. |
||
25 | * |
||
26 | * @param string $key |
||
27 | * @return mixed |
||
28 | */ |
||
29 | 6 | public function offsetGet($key) |
|
33 | |||
34 | /** |
||
35 | * @param string $offset |
||
36 | * @param mixed $value |
||
37 | * @return void |
||
38 | */ |
||
39 | public function offsetSet($offset, $value) |
||
47 | |||
48 | /** |
||
49 | * Unset a configuration option. |
||
50 | * |
||
51 | * @inheritdoc |
||
52 | */ |
||
53 | public function offsetUnset($key) |
||
57 | } |
||
58 |
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.