SoapFault 构造函数的第一个参数 faultcode 必须是字符串。否则会导致错误。
<?php
throw new SoapFault(1, "Error message!"); // 错误
throw new SoapFault("1", "Error message!"); // 正确
?>(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", "Some error message");
}
$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", "Some error message");
}
$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->addFunction("test");
$server->handle();
?>SoapFault 构造函数的第一个参数 faultcode 必须是字符串。否则会导致错误。
<?php
throw new SoapFault(1, "Error message!"); // 错误
throw new SoapFault("1", "Error message!"); // 正确
?>