| 1 | <?php |
||
| 7 | class Base extends ClosedElement |
||
| 8 | { |
||
| 9 | protected function getAllowedAttributes() |
||
| 10 | { |
||
| 11 | $baseAllowedAttributes = array( |
||
| 12 | '/^href$/i' => Element::ATTR_URI, |
||
| 13 | '/^target$/i' => Element::ATTR_CS_STRING |
||
| 14 | ); |
||
| 15 | |||
| 16 | return array_merge( |
||
| 17 | $baseAllowedAttributes, |
||
| 18 | parent::getAllowedAttributes() |
||
| 19 | ); |
||
| 20 | } |
||
| 21 | |||
| 22 | public function validate(Configuration $configuration) |
||
| 52 | } |
||
| 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: