| 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 | public function offsetGet($key) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Set a configuration option. |
||
| 36 | * |
||
| 37 | * @param string $key |
||
| 38 | * @param mixed $value |
||
| 39 | * @return void |
||
| 40 | */ |
||
| 41 | public function offsetSet($key, $value) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Unset a configuration option. |
||
| 48 | * |
||
| 49 | * @param string $key |
||
| 50 | * @return void |
||
| 51 | */ |
||
| 52 | public function offsetUnset($key) |
||
| 56 | } |
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
Idableprovides a methodequalsIdthat 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.