| 1 | <?php |
||
| 22 | class Module implements Feature\AutoloaderProviderInterface, Feature\ConfigProviderInterface, Feature\BootstrapListenerInterface |
||
| 23 | { |
||
| 24 | |||
| 25 | public function getConfig() |
||
| 29 | |||
| 30 | public function getAutoloaderConfig() |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Listen to the bootstrap event. |
||
| 51 | * |
||
| 52 | * @param EventInterface|\Zend\Mvc\MvcEvent $e |
||
| 53 | * |
||
| 54 | * @return void |
||
| 55 | */ |
||
| 56 | public function onBootstrap(EventInterface $e) |
||
| 65 | } |
||
| 66 |
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 implementation 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 interface: