1 | <?php |
||
9 | class SoapClientService extends \SoapClient |
||
10 | { |
||
11 | /** |
||
12 | * @var ApiService |
||
13 | */ |
||
14 | protected $apiService; |
||
15 | |||
16 | /** |
||
17 | * @var resource |
||
18 | */ |
||
19 | protected $context; |
||
20 | |||
21 | /** |
||
22 | * SoapClient constructor. |
||
23 | * @param ApiService $apiService |
||
24 | * @param mixed $wsdl |
||
25 | * @param array|null $options |
||
26 | */ |
||
27 | public function __construct(ApiService $apiService, string $wsdl, array $options = null) |
||
41 | |||
42 | /** |
||
43 | * @param string $request |
||
44 | * @param string $location |
||
45 | * @param string $action |
||
46 | * @param int $version |
||
47 | * @param int $oneWay |
||
48 | * @return string |
||
49 | */ |
||
50 | public function __doRequest($request, $location, $action, $version, $oneWay = 0) |
||
56 | |||
57 | /** |
||
58 | * @return resource |
||
59 | */ |
||
60 | public function getStreamContext() |
||
64 | } |
||
65 |
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: