1 | <?php |
||
8 | class Task extends BaseTask |
||
9 | { |
||
10 | /** |
||
11 | * @var int |
||
12 | */ |
||
13 | private $id; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $intervalExpression; |
||
19 | |||
20 | /** |
||
21 | * @return int |
||
22 | */ |
||
23 | public function getId() |
||
27 | |||
28 | /** |
||
29 | * @return mixed |
||
30 | */ |
||
31 | public function getIntervalExpression() |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function setInterval(CronExpression $interval, \DateTime $firstExecution = null, \DateTime $lastExecution = null) |
||
45 | } |
||
46 |
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: