1 | <?php |
||
13 | class SoapClient extends \SoapClient |
||
14 | { |
||
15 | /** |
||
16 | * cURL resource used to make the SOAP request |
||
17 | * |
||
18 | * @var resource |
||
19 | */ |
||
20 | protected $ch; |
||
21 | |||
22 | /** |
||
23 | * Options passed to the client constructor. |
||
24 | * |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $options; |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function __construct($wsdl, array $options = null) |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function __doRequest($request, $location, $action, $version, $one_way = 0) |
||
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function __getLastRequestHeaders() |
||
89 | |||
90 | /** |
||
91 | * Returns the response code from the last request |
||
92 | * |
||
93 | * @return integer |
||
94 | * |
||
95 | * @throws \BadMethodCallException |
||
96 | * If no cURL resource has been initialized. |
||
97 | */ |
||
98 | public function getResponseCode() |
||
108 | |||
109 | /** |
||
110 | * Builds the headers for the request. |
||
111 | * |
||
112 | * @param string $action |
||
113 | * The SOAP action to be performed. |
||
114 | */ |
||
115 | protected function buildHeaders($action) |
||
126 | |||
127 | /** |
||
128 | * Builds an array of curl options for the request |
||
129 | * |
||
130 | * @param string $action |
||
131 | * The SOAP action to be performed. |
||
132 | * @param string $request |
||
133 | * The XML SOAP request. |
||
134 | * @return array |
||
135 | * Array of curl options. |
||
136 | */ |
||
137 | protected function curlOptions($action, $request) |
||
155 | } |
||
156 |
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: