簡體   English   中英

當我關閉錯誤報告后,非必需操作失敗后,PHP仍然會殺死我的腳本

[英]When I turn off error reporting PHP still kills my script after a failed non-essential operation

因此,我嘗試設置一個Behat場景,該場景可以讓我測試Soap呼叫何時通過身份驗證。 我只需要能夠測試此步驟,然后再進行其他測試步驟即可。 好吧,我專門測試未經身份驗證的SOAP服務調用(該服務需要HTTP Auth)。 當我這樣做時,它將生成一個PHP致命錯誤,然后殺死該腳本。

到目前為止,我已經嘗試使用“ @”來抑制錯誤,並在測試的那部分期間調用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

可以解決嗎?

您無法從致命錯誤中恢復,這些錯誤是致命的。

從這個問題開始,PHP中的SoapClient錯誤回退,您可以讓PHP 優雅地死掉。

為了完全避免問題,請檢查服務是否可用,如此處所述: PHP SOAP錯誤捕獲以及此處的SoapClient錯誤回退

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM