gpt4 book ai didi

php - 当我关闭错误报告时,PHP 在非必要操作失败后仍然会杀死我的脚本

转载 作者:行者123 更新时间:2023-12-03 08:33:18 25 4
gpt4 key购买 nike

因此,我正在尝试设置一个 Behat 场景,让我可以测试 SOAP 调用何时未能通过身份验证。我只需要能够测试这一步,然后进入其他测试步骤。好吧,我正在专门测试对没有身份验证的 SOAP 服务的调用(该服务需要 HTTP Auth)。当我这样做时,它会生成一个 PHP fatal error ,然后终止脚本。

到目前为止,我已经尝试使用“@”来抑制错误并在测试的那部分调用 error_reporting(0) 来关闭错误报告。但它仍然会杀死脚本。有没有办法解决?

public function iConnectToASoapServiceAt($soapURL) {
$this->soapURL = $soapURL;
$errorReporting = error_reporting(); //Save the current error reporting level
error_reporting(0); //Turn off error reporting before we try this

try {
$this->client = @new Zend\Soap\Client($soapURL, $this->options);
$this->soapFunctions = $this->client->getFunctions();
}
catch (\Exception $e) {
#For testing when it fails we cannot actually throw an error here.
#throw new Exception("Error connecting to SOAP server.");
}

error_reporting($errorReporting);
}

这是错误:
PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from

有什么办法吗?

最佳答案

您无法从 fatal error 中恢复,那是致命的。

从这个问题 SoapClient error fallback in PHP你可以让 PHP 优雅地死去。

为完全避免该问题,请检查该服务是否可用,如下所述:PHP SOAP error catching在这里SoapClient error fallback in PHP

关于php - 当我关闭错误报告时,PHP 在非必要操作失败后仍然会杀死我的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17371630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com