| 1 | <?php |
||
| 2 | class Intraface_Controller_ModuleGatekeeper extends k_Component |
||
| 3 | { |
||
| 4 | protected $template; |
||
| 5 | protected $mdb2; |
||
| 6 | |||
| 7 | function __construct(k_TemplateFactory $template, MDB2_Driver_Common $mdb2) |
||
| 12 | |||
| 13 | function map($name) |
||
| 27 | |||
| 28 | function renderHtml() |
||
| 37 | |||
| 38 | public function getKernel() |
||
| 42 | |||
| 43 | function getUser() |
||
| 47 | |||
| 48 | function getModules() |
||
| 55 | } |
||
| 56 |
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: