PHP Conference Japan 2024

SoapServer::fault

(PHP 5, PHP 7, PHP 8)

SoapServer::fault發出 SoapServer 錯誤以指示錯誤

說明

public SoapServer::fault(
    字串 $code,
    字串 $string,
    字串 $actor = "",
    混合 $details = null,
    字串 $name = ""
):

傳送一個錯誤回應給目前請求的客戶端。

注意事項:

這個函式只能在處理請求時呼叫。

參數

code

要返回的錯誤碼

string

錯誤的簡短描述

actor

識別造成錯誤的參與者的字串。

details

錯誤的更多細節

name

錯誤的名稱。這可以用來從 WSDL 檔案中選擇一個名稱。

回傳值

不返回任何值。

另請參閱

新增註釋

使用者貢獻的註釋 4 則註釋

Amr Mostafa
15 年前
此函式目前也會終止執行,這可能並非所期望的。請參閱: http://bugs.php.net/bug.php?id=49513
匿名
16 年前
如果您使用 Adobe Flex、Flash 或 AIR 作為 SOAP 客戶端,並且在發生 soap 錯誤時無法取得錯誤訊息,請升級到 PHP 5.2.6。

詳情請見
http://bugs.php.net/bug.php?id=43507
christian at cmjdesign dot dk
11 年前
嗨,
要控制錯誤輸出,可以執行以下操作

/**
* mySoapServer 類別
*/
class mySoapServer extends SoapServer {
public function __construct($wsdl, array $options = null) {
parent::SoapServer($wsdl, $options);
}
public function fault ($code, $string, $actor = null, $details = null, $name = null) {
throw new SoapFault($code, $string, $actor, $details, $name);
}
}

使用
try {
$server = new mySoapServer(null, array('uri' => $_SERVER['REQUEST_URI']));
$server->setClass('mySoapAPI');
$server->handle();
} catch (SoapFault $exc) {
echo $exc->getTraceAsString();
}

這就是我的做法,
希望這能幫助到一些人。
dub357 at gmail dot com
12 年前
此函式還會將 500 回應碼傳送回客戶端。
這會在我的 Apache Axis 1.2 客戶端上造成問題,所以我改用自行實作的錯誤處理。

<?php
header
("Content-Type: text/xml");
header("Status: 200");
die(
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\\"http://schemas.xmlsoap.org/soap/envelope/\\">
<SOAP-ENV:Body>
<
SOAP-ENV:Fault>
<
faultcode>500</faultcode>
<
faultstring>".$ex->getMessage())."</faultstring>
</
SOAP-ENV:Fault>
</
SOAP-ENV:Body>
</
SOAP-ENV:Envelope>");
?>
To Top