1 | <?php |
||
10 | trait Query { |
||
11 | /** |
||
12 | * Query array, similar to `$_GET` |
||
13 | * |
||
14 | * @var array |
||
15 | */ |
||
16 | public $query; |
||
17 | /** |
||
18 | * @param array $query Typically `$_GET` |
||
19 | */ |
||
20 | 28 | public function init_query ($query = []) { |
|
23 | /** |
||
24 | * Get query parameter by name |
||
25 | * |
||
26 | * @param string[]|string[][] $name |
||
27 | * |
||
28 | * @return mixed|mixed[]|null Query parameter (or associative array of Query parameters) if exists or `null` otherwise (in case if `$name` is an array |
||
29 | * even one missing key will cause the whole thing to fail) |
||
30 | */ |
||
31 | 2 | public function query (...$name) { |
|
34 | } |
||
35 |
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.