PHP Conference Japan 2024

SoapFault::__construct

(PHP 5, PHP 7, PHP 8)

SoapFault::__constructSoapFault 建構子

說明

public SoapFault::__construct(
    陣列|字串|null $code,
    字串 $string,
    ?字串 $actor = null,
    混合 $details = null,
    ?字串 $name = null,
    混合 $headerFault = null
)

這個類別用於從 PHP 處理程式發送 SOAP 錯誤回應。 faultcodefaultstringfaultactordetail 是 SOAP 錯誤的標準元素。

參數

faultcode

SoapFault 的錯誤碼。

faultstring

SoapFault 的錯誤訊息。

faultactor

識別導致錯誤的參與者的字串。

detail

關於錯誤原因的更多詳細資訊。

faultname

可用於從 WSDL 中選擇正確的錯誤編碼。

headerfault

可以在 SOAP 標頭處理期間使用,以回報回應標頭中的錯誤。

範例

範例 #1 一些範例

<?php
function test($x)
{
return new
SoapFault("Server", "一些錯誤訊息");
}

$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->addFunction("test");
$server->handle();
?>

可以使用 PHP 例外機制來拋出 SOAP 錯誤。

範例 #2 一些範例

<?php
function test($x)
{
throw new
SoapFault("Server", "一些錯誤訊息");
}

$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->addFunction("test");
$server->handle();
?>

另請參閱

新增註釋

使用者提供的註釋 1 則註釋

3
csnaitsirch at web dot de
14 年前
SoapFault 建構函式的第一個參數,也就是 faultcode,必須是字串。否則會導致錯誤。

<?php
throw new SoapFault(1, "錯誤訊息!"); // 錯誤
throw new SoapFault("1", "錯誤訊息!"); // 正確
?>
To Top