1 | <?php |
||
5 | class TypeUtils |
||
6 | { |
||
7 | /** |
||
8 | * Check if value is a valid cURL handle. |
||
9 | * @param mixed $value |
||
10 | * @return bool |
||
11 | */ |
||
12 | 32 | public static function isCurl($value) |
|
16 | |||
17 | /** |
||
18 | * Check if value is a valid Generator. |
||
19 | * @param mixed $value |
||
20 | * @return bool |
||
21 | */ |
||
22 | 29 | public static function isGeneratorContainer($value) |
|
26 | |||
27 | /** |
||
28 | * Check if value is a valid Generator closure. |
||
29 | * @param mixed $value |
||
30 | * @return bool |
||
31 | */ |
||
32 | 33 | public static function isGeneratorClosure($value) |
|
37 | } |
||
38 |
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: