1 | <?php |
||
10 | class MaterialField extends \samson\activerecord\materialfield |
||
11 | { |
||
12 | /** |
||
13 | * Find additional field value database record by its material and field identifiers. |
||
14 | * This is generic method that should be used in nested classes to find its |
||
15 | * records by some its primary key value. |
||
16 | * |
||
17 | * @param QueryInterface $query Query object instance |
||
18 | * @param string $materialID Material identifier |
||
19 | * @param string $fieldID Additional field identifier |
||
20 | * @param self $return Variable to return found database record |
||
21 | * @param string $locale Locale identifier |
||
22 | * @return bool|null|self Field instance or null if 3rd parameter not passed |
||
23 | */ |
||
24 | public static function byFieldIDAndMaterialID( |
||
40 | } |
||
41 |
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 implementation 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 interface: