1 | <?php |
||
12 | class Urlset implements OutputInterface |
||
13 | { |
||
14 | /** |
||
15 | * Array of URL objects. |
||
16 | * |
||
17 | * @var OutputInterface[] |
||
18 | */ |
||
19 | protected $urls = []; |
||
20 | |||
21 | /** |
||
22 | * Sub-elements that have been appended to the collection attributes. |
||
23 | * |
||
24 | * @var AppendAttributeInterface[] |
||
25 | */ |
||
26 | protected $appendedSubelements = []; |
||
27 | |||
28 | /** |
||
29 | * Add a new URL object. |
||
30 | * |
||
31 | * @param OutputInterface $url |
||
32 | * |
||
33 | * @return $this |
||
34 | */ |
||
35 | public function addUrl(OutputInterface $url) |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public function generateXML(XMLWriter $XMLWriter) |
||
69 | |||
70 | /** |
||
71 | * Get array of URL objects. |
||
72 | * |
||
73 | * @return OutputInterface[] |
||
74 | */ |
||
75 | public function getUrls() |
||
79 | |||
80 | /** |
||
81 | * Appends the sub-element to the collection attributes if it has yet to be visited. |
||
82 | * |
||
83 | * @param XMLWriter $XMLWriter |
||
84 | * @param OutputInterface $subelement |
||
85 | * |
||
86 | * @return boolean |
||
87 | */ |
||
88 | public function appendSubelementAttribute(XMLWriter $XMLWriter, OutputInterface $subelement) |
||
99 | } |
||
100 |
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: