| 1 | <?php |
||
| 17 | abstract class AbstractPropertyNotThingableError extends TypeError |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Wraps to TypeError::__construct(). |
||
| 21 | * |
||
| 22 | * @param string $thing the type of thing that the $property cannot do, i.e. writeable, nullable |
||
| 23 | * @param string $className name of the class on which the property is not thingable |
||
| 24 | * @param string $property name of the property which is not thingable |
||
| 25 | * @param int $code @see TypeError::__construct() |
||
| 26 | * @param Throwable|null $previous @see TypeError::__construct() |
||
| 27 | */ |
||
| 28 | public function __construct( |
||
| 46 | } |
||
| 47 |
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 sub-classes 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 parent class: