| 1 | <?php |
||
| 10 | class CallbackRecursiveIterator extends CachingIterator implements RecursiveIterator |
||
| 11 | { |
||
| 12 | protected $getChildrenCallback; |
||
| 13 | protected $currentChildrenCache; |
||
| 14 | protected $isCurrentChildrenCacheValid = false; |
||
| 15 | |||
| 16 | public function __construct($startNodes, $getChildrenCallback) |
||
| 21 | |||
| 22 | public function getChildren() |
||
| 35 | |||
| 36 | public function hasChildren() |
||
| 40 | |||
| 41 | public function next() |
||
| 46 | |||
| 47 | public function rewind() |
||
| 52 | } |
||
| 53 | |||
| 54 |
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: