1 | <?php |
||
8 | class Utils { |
||
9 | |||
10 | /** |
||
11 | * Recursively normalize value. |
||
12 | * Generator Closure -> GeneratorContainer |
||
13 | * Array -> Array (children's are normalized) |
||
14 | * Others -> Others |
||
15 | * @param mixed $value |
||
16 | * @param CoOption $options |
||
17 | * @param mixed $yield_key |
||
18 | * @return mixed |
||
19 | */ |
||
20 | public static function normalize($value, CoOption $options, $yield_key = null) |
||
37 | 13 | ||
38 | 9 | /** |
|
39 | 9 | * Recursively search yieldable values. |
|
40 | 9 | * Each entries are assoc those contain keys 'value' and 'keylist'. |
|
41 | * value -> the value itself. |
||
42 | 8 | * keylist -> position of the value. nests are represented as array values. |
|
43 | * @param mixed $value Must be already normalized. |
||
44 | 13 | * @param array $keylist Internally used. |
|
45 | * @return array |
||
46 | */ |
||
47 | public static function getYieldables($value, array $keylist = []) |
||
65 | |||
66 | 13 | /** |
|
67 | * Check if value is a valid cURL handle. |
||
68 | 8 | * @param mixed $value |
|
69 | 8 | * @return bool |
|
70 | 8 | */ |
|
71 | public static function isCurl($value) |
||
75 | |||
76 | /** |
||
77 | * Check if value is a valid Generator. |
||
78 | * @param mixed $value |
||
79 | * @return bool |
||
80 | 14 | */ |
|
81 | 14 | public static function isGeneratorContainer($value) |
|
85 | |||
86 | /** |
||
87 | * Check if value is a valid Generator closure. |
||
88 | * @param mixed $value |
||
89 | * @return bool |
||
90 | 14 | */ |
|
91 | 14 | public static function isGeneratorClosure($value) |
|
96 | |||
97 | } |
||
98 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: