PHP没有那么致命的错误,带有;新建SoapClient();
我运行了以下代码段:PHP没有那么致命的错误,带有;新建SoapClient();,php,soap-client,Php,Soap Client,我运行了以下代码段: foreach($config as $wsInfo){ try{ $soapClient = new SoapClient($wsInfo['url'], array('encoding'=>'ISO-8859-1')); // Some more code that I commented out. } catch(Exception $e){ echo
foreach($config as $wsInfo){
try{
$soapClient = new SoapClient($wsInfo['url'],
array('encoding'=>'ISO-8859-1'));
// Some more code that I commented out.
}
catch(Exception $e){
echo "EXCEPTION: \n" . $e->getMessage();
// log it, etc.
}
}
当我运行该程序时,Web服务URL会向我发送一个身份验证错误(在开发阶段这是正常的)
我注意到的外星人的行为是,当我期待这个的时候:
$ php scan.php -p=/ -c=config.yml
EXCEPTION:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
EXCEPTION:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
它给了我这个:
$ php scan.php -p=/ -c=config.yml
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
in /home/me/project/DFPushSOAP.php on line 34
EXCEPTION:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
in /home/me/project/DFPushSOAP.php on line 34
EXCEPTION:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
为什么“PHP致命错误”不会杀死程序?为什么它要逃离try/catch块
我怎样才能避免这种情况呢?我也遇到了同样的问题,并找到了解决方案 首先,您应该设置
异常
选项以强制SoapClient抛出异常:
$soapClient = new SoapClient($wsInfo['url'], array('encoding'=>'ISO-8859-1'
'exceptions' => true ));
在我的例子中,xdebug强制生成一个致命错误,而不是一个可捕获的异常。
因此,您应该尝试禁用xdebug来创建SoapClient:
if(function_exists('xdebug_disable')){ xdebug_disable(); };
$soapClient = new SoapClient($wsInfo['url'], array('encoding'=>'ISO-8859-1'
'exceptions' => true ));
if(function_exists('xdebug_enable')){ xdebug_enable(); };
希望这能帮助您^^暂时禁用xdebug的解决方案对我来说不起作用(运行PHP7.0.12/amd64)启用了xdebug) 在显示带有自定义临时错误处理程序的解决方案时,回答了上述错误。参见英国computerminds dot co dot公司james dot silver发布的帖子[2012-10-03 09:36 UTC] 作为一种肮脏的解决方法,您可以停用
错误报告()
但是自定义错误处理程序看起来更令人愉快。看
$level = error_reporting();
error_reporting(0);
$soapClient = new SoapClient($wsInfo['url'], array(
'encoding'=>'ISO-8859-1'
'exceptions' => true )
);
error_reporting($level);