1 | <?php |
||
8 | class TreeNode extends Node { |
||
9 | |||
10 | /** |
||
11 | * SRFTreeElement constructor. |
||
12 | * @param \SMWResultArray[] | null $row |
||
13 | */ |
||
14 | public function __construct( $row = null ) { |
||
17 | |||
18 | /** |
||
19 | * @return string |
||
20 | */ |
||
21 | public function getHash() { |
||
31 | |||
32 | /** |
||
33 | * @return null|\SMWDIWikiPage |
||
34 | */ |
||
35 | public function getResultSubject() { |
||
45 | |||
46 | public function addChild( NodeInterface $child ) { |
||
56 | |||
57 | |||
58 | } |
||
59 | |||
60 |
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: