1 | <?php |
||
10 | class Table implements \Iterator |
||
11 | { |
||
12 | private $viewFactory; |
||
13 | private $gridMetadata; |
||
14 | private $collection; |
||
15 | |||
16 | public function __construct( |
||
25 | |||
26 | public function current() |
||
34 | |||
35 | public function next() |
||
39 | |||
40 | public function key() |
||
44 | |||
45 | public function rewind() |
||
49 | |||
50 | public function valid() |
||
54 | } |
||
55 |
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: