SoapFault 建構函式的第一個參數,也就是 faultcode,必須是字串。否則會導致錯誤。
<?php
throw new SoapFault(1, "錯誤訊息!"); // 錯誤
throw new SoapFault("1", "錯誤訊息!"); // 正確
?>
(PHP 5, PHP 7, PHP 8)
SoapFault::__construct — SoapFault 建構子
$code
,$string
,$actor
= null
,$details
= null
,$name
= null
,$headerFault
= null
這個類別用於從 PHP 處理程式發送 SOAP 錯誤回應。 faultcode
、faultstring
、faultactor
和 detail
是 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();
?>
SoapFault 建構函式的第一個參數,也就是 faultcode,必須是字串。否則會導致錯誤。
<?php
throw new SoapFault(1, "錯誤訊息!"); // 錯誤
throw new SoapFault("1", "錯誤訊息!"); // 正確
?>