1 | <?php |
||
8 | class AjaxDetailsRow extends DetailsRow |
||
9 | { |
||
10 | |||
11 | protected $urlGenerator; |
||
12 | |||
13 | public function __construct(callable $urlGenerator, ResourceManager $resourceManager = null) |
||
20 | |||
21 | /** |
||
22 | * @return callable |
||
23 | */ |
||
24 | public function getUrlGenerator() |
||
28 | |||
29 | /** |
||
30 | * @param callable $urlGenerator |
||
31 | * @return $this |
||
32 | */ |
||
33 | public function setUrlGenerator(callable $urlGenerator) |
||
38 | |||
39 | public function render() |
||
44 | |||
45 | protected function getScriptSource() |
||
59 | } |
||
60 |
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: