Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Possibility to turn off warnings (as they are redundant due to Exceptions being thrown) #55

Open
njandreasson opened this issue Jun 19, 2018 · 3 comments

Comments

@njandreasson
Copy link

I'm wondering whether it would make sense to be able to turn off warnings coming from SoapClient as I would assume that most people are relying on Exceptions for error-handling?

For example, we use it like this:

<?php
try {
    $client = new \Zend\Soap\Client('https://example.org/?wsdl', [
        'soap_version' => SOAP_1_1,
        'location'     => 'https://example.org/'
    ]);
    $client->myCommand([
        'arg' => 'value'
    ]);
} catch (SoapFault $exception) {
    // Error handling code
}

Occasionally if there's a communication error with the remote endpoint a PHP warning will be logged like this:

[Tue Jun 19 02:14:31 2018] [error] [client x.x.x.x] PHP Warning: SoapClient::__doRequest(): SSL: Connection reset by peer in /xx/vendor/zendframework/zend-soap/src/Client.php on line 1039

At the same time a SoapFaul exception is thrown which is what we use for error-handling so the warning just clogs up our error logs unnecessarily as we're already handling the situation properly.

We're using version 2.7.0 meaning this line points to https://github.com/zendframework/zend-soap/blob/release-2.7.0/src/Client.php#L1032 where SoapClient::__doRequest is called.

I notice that the PHP manual doesn't actually mention that __doRequest can emit warnings, that might in itself be a glitch to file a bug report for regarding the ext-soap documentation?

Anyhow, even if it would be documented we would still need to silence the warnings in zend-soap if they are not wanted.

Would it make sense to switch to return @call_user_func() or introduce a toggle that disables PHP warnings in zend-soap?

Many thanks!

@Ocramius
Copy link
Member

Silencing is not an option: explicit suppression with an error handler that is restored immediately after the call is a better solution, but the error handler must only take warnings and convert them to exceptions

@njandreasson
Copy link
Author

Well, in this particular case as I stated a SoapFault Exception is already being thrown as that's what I successfully use for my error handling. That's why the warning is meaningless to me, hence my suggestion that simply silencing might be an alternative.

Maybe something like this would do the trick?

// Catch warnings (to prevent them from being logged)
set_error_handler(function ($errno, $errstr) {
    // Intentional no-op
}, E_WARNING);

$response = call_user_func(
    [$client, 'SoapClient::__doRequest'],
    $request,
    $location,
    $action,
    $version,
    $oneWay
);

// Restore previous error handler again
restore_error_handler();

return $response;

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas/laminas-soap; a new issue has been opened at laminas/laminas-soap#6.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants