Bug #76070 [NEW]: SoapServer::handle() catches some exceptions, but not all
| From: | magnar at myrtveit dot com | Date: | Thu, 08 Mar 2018 18:37:13 +0000 |
| Subject: | Bug #76070 [NEW]: SoapServer::handle() catches some exceptions, but not all | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-214240@lists.php.net to get a copy of this message | ||
From: magnar at myrtveit dot com
Operating system: Windows
PHP version: 7.1.15
Package: SOAP related
Bug Type: Bug
Bug description:SoapServer::handle() catches some exceptions, but not all
Description:
------------
Sometimes exceptions are caught by SoapServer::handle(), and sometimes
not. Particularly, exceptions of type Error are caught, while exceptions
of type Exception are not.
Consider the test script. There are two lines throwing exceptions that
are commented out.
By sending a request to the soap server, the file
response.txt is
created with the expected soap response.
By uncommenting the first exception (1) and sending a request to the
soap server, the file exception.txt is created with the following
contents:
Uncaught exception: bar
By uncommenting the second exception (2) and sending a request to the
soap server, the file exception.txt is not created! But the file
response.txt is created with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>foo</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
It is surprising that the second exception never reaches the exception
handler. Instead, the exception seems to be caught inside
SoapServer::handle(), and the exception message is sent as a soap fault
to the client.
Test script:
---------------
Server script, uncomment the exceptions, one after the other, to see the
strange behavior:
<?php
set_exception_handler(function(Throwable $Exception) {
file_put_contents(__DIR__.'/exception.txt', 'Uncaught exception:
'.$Exception->getMessage());
});
function SoapFunction() {
// throw new Exception('bar'); // (1) Invokes the exception handler
// throw new Error('foo'); // (2) Does not invoke the exception
handler!
}
$Server = new SoapServer(null, ['uri' => 'MyNamespace']);
$Server->addFunction('SoapFunction');
ob_start();
$Server->handle();
file_put_contents(__DIR__.'/response.txt', ob_get_flush());
Client script, change http://www.example.com/server.php so that it
points to the server script above:
<?php
$Client = new SoapClient(null, ['uri' => 'MyNamespace', 'location'
=>
'http://www.example.com/server.php']);
$Client->__soapCall('SoapFunction', []);
Expected result:
----------------
By uncommenting the second exception (2) and sending a request to the
soap server, I would expect that the file exception.txt was created
with the following contents:
Uncaught exception: foo
Actual result:
--------------
By uncommenting the second exception (2) and sending a request to the
soap server, the file response.txt is created with the following
contents:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>foo</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
--
Edit bug report at https://bugs.php.net/bug.php?id=76070&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76070&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76070&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76070&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76070&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76070&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76070&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76070&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76070&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76070&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76070&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76070&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76070&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76070&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76070&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76070&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76070&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76070&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76070&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76070&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76070&r=mysqlcfg