New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed compatibility with SoapClient #7140
Conversation
I found these snippets: https://psalm.dev/r/e7364a92c6<?php
function getRequestId(SoapClient $service): ?string
{
$headers = $service->__getLastResponseHeaders();
if ($headers !== null && preg_match('/^RequestId:\s?(.+)$/im', $headers, $m)) {
return $m[1];
}
return null;
}
|
@veewee You recently submitted changes in soap stubs, do you mind reviewing this PR if you're familiar with the extension? |
@@ -12266,7 +12266,7 @@ | |||
'SoapFault::getPrevious' => ['?Exception|?Throwable'], | |||
'SoapFault::getTrace' => ['list<array<string,mixed>>'], | |||
'SoapFault::getTraceAsString' => ['string'], | |||
'SoapFault::SoapFault' => ['object', 'faultcode'=>'string', 'faultstring'=>'string', 'faultactor='=>'string', 'detail='=>'string', 'faultname='=>'string', 'headerfault='=>'string'], | |||
'SoapFault::SoapFault' => ['object', 'faultcode'=>'string', 'faultstring'=>'string', 'faultactor='=>'string', 'detail='=>'mixed', 'faultname='=>'string', 'headerfault='=>'string'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the details is ok, but the other props also don't seem to match the signature of SoapFault::__construct()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the constructor signature according to the documentation. And also the property map has been updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orklah : Do the names of these parameters matter (e.g. for named params)?
Since It is actually:
#[Pure]
public function __construct(
array|string|null $code,
string $string,
?string $actor = null,
mixed $details = null,
?string $name = null,
mixed $headerFault = null
) {
See:
- https://github.com/php/php-src/blob/1d54097435bc09a287cb50b6e166eccba19f2925/ext/soap/soap.stub.php#L38
- https://github.com/php/php-src/blob/1d54097435bc09a287cb50b6e166eccba19f2925/ext/soap/soap_arginfo.h#L25-L32
(It is more like an internal exception though, but maybe you'dd be creating it for testing purpose)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Names do matter, for when Psalm checks calls with named arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the signatures for SoapFault::__construct() and SoapFault::SoapFault().
@orklah Seems correct and documented: I can imageine that they have always worked like this. These can return null in non-wsdl mode or when overriding construct and calling these functions withouth the WSDL being parsed:
$soap = new SoapClient(null, [
'location' => 'http://127.0.0.1',
'uri' => 'http://127.0.0.1',
]);
var_dump($soap->__getFunctions());
// > null
var_dump($soap->__getTypes());
// > null These will return null if trace is disabled (or if the connection got a timeout - you can simulate this with the ini setting
$soap = new SoapClient('http://www.dneonline.com/calculator.asmx?wsdl', [
'trace' => 0,
]);
$result = $soap->Add(['intA' => 1, 'intB' => 2]);
var_dump($soap->__getLastRequest());
// > null
var_dump($soap->__getLastRequestHeaders());
// > null
var_dump($soap->__getLastResponse());
// > null
var_dump($soap->__getLastResponse());
// > null The SoapFault indeed takes a ?mixed details prop. |
test-with-real-projects/PHPUnit failure seems legit. You may want to PR a null check to PHPUnit, but for the purposes of our CI suite we will just baseline that error when it's merged. |
Thanks! @weirdan can you update the baseline for phpunit? |
SoapClient
Some methods can return
null
but currently these cases are not detected by psalm. As instance,__getLastResponse()
returnsnull
when connection was closed before receiving a response.https://psalm.dev/r/e7364a92c6
If we remove the check for
null
, then can get an error of incompatibility types, at runtime:Affected methods:
__getFunctions
__getLastRequest
__getLastRequestHeaders
__getLastResponse
__getLastResponseHeaders
__getTypes
SoapFault
Value of property
detail
can be mixed.