| 1 | <?php |
||
| 16 | class ConversationSubscriber implements EventSubscriberInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Returns all the events that this subscriber handles, and which method |
||
| 20 | * handles each one |
||
| 21 | * |
||
| 22 | * @return array |
||
| 23 | */ |
||
| 24 | public static function getSubscribedEvents() |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Called every time a member is added/removed from a team |
||
| 35 | * |
||
| 36 | * @param TeamAbandonEvent|TeamJoinEvent|TeamKickEvent $event The event |
||
| 37 | * @param string $type The type of the event |
||
| 38 | */ |
||
| 39 | public function onTeamMembershipChange(Event $event, $type) |
||
| 47 | } |
||
| 48 |
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: