- PHP 手册
- 函数参考
- Web 服务
- SOAP
The SoapFault class
(PHP 5, PHP 7, PHP 8)
简介
Represents a SOAP fault.
类摘要
class SoapFault extends Exception { /* 属性 */ public string $faultstring; public ?string $faultcode = null; public ?string $faultcodens = null; public ?string $faultactor = null; public mixed $detail = null; public ?string $_name = null; public mixed $headerfault = null; /* 继承的属性 */ protected string $message = ""; private string $string = ""; protected int $code; protected string $file = ""; protected int $line; private array $trace = []; private ?Throwable $previous = null; /* 方法 */ public __construct(array|string|null
$code
,string
$string
,?string
$actor
= null
,mixed
$details
= null
,?string
$name
= null
,mixed
$headerFault
= null
) public __toString(): string /* 继承的方法 */ final public Exception::getMessage(): string final public Exception::getPrevious(): ?Throwable final public Exception::getCode(): int final public Exception::getFile(): string final public Exception::getLine(): int final public Exception::getTrace(): array final public Exception::getTraceAsString(): string public Exception::__toString(): string private Exception::__clone(): void }
属性
- _name
-
- detail
-
- faultactor
-
- faultcode
-
- faultcodens
-
- faultstring
-
- headerfault
-
目录
- SoapFault::__construct — SoapFault constructor
- SoapFault::__toString — Obtain a string representation of a SoapFault
User Contributed Notes 3 notes
up down 41 dmitry dot koterov at gmail dot com ¶12 years ago
You may use undocumented and invisible property $e->faultcode to access string version of $code. Because standard $e->getCode() does not work:
<?php
$e = new SoapFault("test", "msg");
var_dump($e->getCode()); // prints "0"
var_dump($e->faultcode); // prints "test"
?>
Also you may use namespaced fault codes:
<?php
$e = new SoapFault(array("namespace", "test"), "msg");
?>
- see ext/soap/soap.php, PHP_METHOD(SoapFault, SoapFault). To access the namespace, use $e->faultcodens
up
down
9
chris AT cmbuckley DOT co DOT uk ¶12 years ago
A bit more digging in ext/soap/soap.c and the set_soap_fault function reveals the other undocumented properties from the constructor:
<?php
try {
throw new SoapFault('code', 'string', 'actor', 'detail', 'name', 'header');
} catch (Exception $ex) {
var_dump($ex->faultcode, $ex->faultstring, $ex->faultactor, $ex->detail, $ex->_name, $ex->headerfault);
}
?>
up
down
4
fbernoldi at gmail dot com ¶9 years ago
Hi all,
I've decided to post this since it may be helpful, I've spend a couple of days trying to do this.
In order to use wsdl's specified faults with complex types, i.e:
WSDL definitions:
(xsd:schema namespace, ns1 = target namespace)
<xsd:element name="doubleFault">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="detail1" type="xsd:string"/>
<xsd:element name="detail2" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
WSDL messages:
<message name="fault_specified">
<part name="relevant_name" element="ns1:doubleFault"/>
</message>
WSDL port type:
<portType name="test">
<operation name="operationTest">
<input message="ns1:not_relevant_request"/>
<output message="ns1:not_relevant_response"/>
<fault name="FaultSpecified" message="ns1:fault_specified"/>
....
</portType>
You have to specify the response in the detail parameter as an array corresponding the tag names.
PHP Code:
<?php
function operationTest($request_param ...) {
// ...
$array_details = array("detail1" => "Explanation 1", "detail2" => "Explanation 2");
return new SoapFault("Server", "example fault string", null, $array_details, "FaultSpecified");
}
$server = new SOAPServer("handmade.wsdl");
$server->addFunction("operationTest");
$server->handle();
?>
that should respond something like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://mynamespace">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>example fault string</faultstring>
<detail>
<ns1:doubleFault>
<detail1>Explanation 1</detail1>
<detail2>Explanation 2</detail2>
</ns1:doubleFault>
</detail>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I Hope it helps,
Federico.
add a note
官方地址:https://www.php.net/manual/en/class.soapfault.php
8288分类目录声明:本站部分文章来源于网络,版权属于原作者所有。如有转载或引用文章/图片涉及版权问题,请联系我们处理.我们将在第一时间删除!
联系邮箱:tsk@qq.com