1 | <?php |
||
15 | class HtmlIconGroups extends HtmlSemCollection { |
||
16 | |||
17 | public function __construct($identifier, $icons=array(), $size="") { |
||
22 | |||
23 | protected function createItem($value) { |
||
35 | |||
36 | protected function createCondition($value) { |
||
39 | |||
40 | public function getIcon($index) { |
||
43 | |||
44 | public function run(JsUtils $js){ |
||
48 | |||
49 | public function toCorner($index=1) { |
||
53 | } |
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: