Firstly I would like to apologise if this issue has come up already in Stack Overflow but my googling did not manage to find it.
I'm running on PHP 7.2 and have created a SoapClient to send RPC encoded requests to a Web Service.
$this->client = new \SoapClient('https://tsp.demo.sk.ee/dds.wsdl', [
'soap_version' => SOAP_1_1,
'cache_wsdl' => WSDL_CACHE_NONE,
'trace' => true,
'style' => SOAP_RPC,
'use' => SOAP_ENCODED,
]);
I now tried to use this client to send a request to the MobileAuthenticate request and use named parameters to do it since I don't need to fill in all of the available parameters.
$params = [
'CountryCode' => 'EE',
'PhoneNo' => '+3xxxxxxxxxx',
'Language' => 'ENG',
'ServiceName' => 'Testimine',
'MessageToDisplay' => 'Test Message',
'SPChallenge' => '12345678901234567890',
'MessagingMode' => 'asynchClientServer',
];
try {
$response = $this->client->MobileAuthenticate($params);
dd($response);
} catch (\SoapFault $e) {
var_dump($e);
var_dump($this->client->__getLastRequest());
var_dump($this->client->__getLastResponse());
}
I was getting back that the language code was incorrect but based on the Web Service documentation, it was. I then started examining the output of $this->client->__getLastRequest() and found out that the method call was taking the parameters in an ordered array fashion. It set the first parameter value as Array.
I examined the SoapFault exception output and indeed, my named parameters were nested in another array
["args"]=>
array(2) {
[0]=>
string(18) "MobileAuthenticate"
[1]=>
array(1) {
[0]=>
array(8) {
["IDCode"]=>
string(0) ""
["CountryCode"]=>
string(2) "EE"
["PhoneNo"]=>
string(12) "+3xxxxxxxxxx"
["Language"]=>
string(3) "ENG"
["ServiceName"]=>
string(9) "Testimine"
["MessageToDisplay"]=>
string(12) "Test Message"
["SPChallenge"]=>
string(20) "12345678901234567890"
["MessagingMode"]=>
string(18) "asynchClientServer"
}
}
}
I've tried googling for similar issues and everything I found (even comments on php.net) show that this is the way to use named parameters, even most nowadays services expect the usage of named parameters.
Several months back I worked on another project running on PHP 5.6 that also consumed a SOAP Web Service and that worked like a charm. SoapClient implementation-wise, the only difference I see is the PHP version.
Am I missing something that has changed since PHP 7 that I can't see in the docs or I'm blindly not seeing the issue?
Small update: I was able to reproduce the issue on Homebrew compiled PHP 5.6, 7.0 and 7.2 as well as on Arch Linux compiled PHP 7.2.
'features' => SOAP_SINGLE_ELEMENT_ARRAYSor'features' => SOAP_USE_XSI_ARRAY_TYPEor both.SOAP_SINGLE_ELEMENT_ARRAYSbefore but it had no affect. I now tried the combination of the two and unfortunately the result was the same.