| 1 | <?php |
||
| 10 | abstract class LayeredNetwork implements Network |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * @var Layer[] |
||
| 14 | */ |
||
| 15 | protected $layers; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param Layer $layer |
||
| 19 | */ |
||
| 20 | public function addLayer(Layer $layer) |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @return Layer[] |
||
| 27 | */ |
||
| 28 | public function getLayers(): array |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @return Layer |
||
| 35 | */ |
||
| 36 | public function getOutputLayer(): Layer |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | public function getOutput(): array |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param mixed $input |
||
| 56 | */ |
||
| 57 | public function setInput($input) |
||
| 65 | } |
||
| 66 |
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: