| 1 | <?php |
||
| 11 | class DebugSoapClient extends SoapClient |
||
| 12 | {
|
||
| 13 | /** |
||
| 14 | * Log file (or stream) to use for logging SOAP requests/responses |
||
| 15 | * @var resource |
||
| 16 | */ |
||
| 17 | protected $logFile = null; |
||
| 18 | |||
| 19 | public function __construct($wsdl, array $options = []) |
||
| 20 | {
|
||
| 21 | if (!array_key_exists('log_file', $options)) {
|
||
| 22 | throw new Exception("Debug soap client requires a log file path provided as \$options['log_file'] to work");
|
||
| 23 | } |
||
| 24 | |||
| 25 | $this->logFile = fopen($options['log_file'], "a"); |
||
| 26 | |||
| 27 | $options['trace'] = 1; |
||
| 28 | |||
| 29 | parent::__construct($wsdl, $options); |
||
|
|
|||
| 30 | } |
||
| 31 | |||
| 32 | |||
| 33 | public function __destruct() |
||
| 37 | |||
| 38 | |||
| 39 | public function __call($functionName, $arguments) |
||
| 49 | |||
| 50 | |||
| 51 | protected function log($message) |
||
| 55 | } |
||
| 56 |
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: