| 1 | <?php |
||
| 17 | abstract class Method |
||
| 18 | { |
||
| 19 | use CondorcetVersion; |
||
| 20 | |||
| 21 | public static $MaxCandidates = null; |
||
| 22 | |||
| 23 | protected $_selfElection; |
||
| 24 | protected $_Result; |
||
| 25 | |||
| 26 | 95 | public function __construct (Election $mother) |
|
| 34 | |||
| 35 | 22 | public function getResult () : Result |
|
| 46 | |||
| 47 | abstract protected function getStats () : array; |
||
| 48 | |||
| 49 | 87 | protected function createResult (array $result) : Result |
|
| 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: