我正在用肥皂工作。当我调用时,我使用try {} catch{}块。我想保存异常错误到数据库中。为了美化代码,我将错误解析到另一个函数中,示例如下:
$paramis = array(
'client' => '225',
'film_id' => '612',
'booking' => '2016-02-28',
'persons' => 1
);
$puri = 'http://www.filmonschedule.com/Portal/break.asmx?WSDL';
$client = new SoapClient($puri, array('trace' => 1, 'exceptions' => 1));
//var_dump($client);
try {
$resp = $client->__soapCall('getFilmToBook', array('parameters' => $paramis));
} catch (Exception $e) {
printErrorMu($e);
}
function printErrorMu($e)
{
print_r($e);
}
这是输出prininterrormu ($e)
SoapFault Object
(
[message:protected] => System.Web.Services.Protocols.SoapException: No Schedule
at Portal.Break.getFilmToBook(String portalName, String client, String film_id, String booking, String persons)
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /var/www/myfilm/test.php
[line:protected] => 245
[trace:Exception:private] => Array
(
[0] => Array
(
[file] => /var/www/myfilm/test.php
[line] => 245
[function] => __soapCall
[class] => SoapClient
[type] => ->
[args] => Array
(
[0] => getFilmToBook
[1] => Array
(
[parameters] => Array
(
[client] => 225
[film_id] => 612
[booking] => 2016-02-28
[persons] => 1
)
)
)
)
)
[previous:Exception:private] =>
[faultstring] => System.Web.Services.Protocols.SoapException: No Schedule
at Portal.Break.getFilmToBook(String portalName, String client, String film_id, String booking, String persons
[faultcode] => soap:Server
[faultactor] => http://www.filmonschedule.com/Portal/break.asmx
[detail] => stdClass Object
(
[exceptionInfo] => No schedule for this booking request
)
)
,但我不能读取参数作为对象/数组内的函数printErrorMu($e)。如何将参数转换为数组或对象,以便我可以访问属性/键的这些值([message:protected][string:Exception:private][code:protected][file:protected][line:protected][trace:Exception:private][previous:Exception:private]) ?
谢谢。
为什么不能呢?使用SoapFault方法:
$e->getMessage();
$e->getPrevious();
...