略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: SoapServer::fault

2024-11-14

SoapServer::fault

(PHP 5, PHP 7, PHP 8)

SoapServer::faultIssue SoapServer fault indicating an error

说明

public SoapServer::fault(
    string $code,
    string $string,
    string $actor = "",
    mixed $details = null,
    string $name = ""
): void

Sends a response to the client of the current request indicating an error.

注意:

This can only be called when handling a request.

参数

code

The error code to return

string

A brief description of the error

actor

A string identifying the actor that caused the fault.

details

More details of the fault

name

The name of the fault. This can be used to select a name from a WSDL file.

返回值

没有返回值。

参见

add a noteadd a note

User Contributed Notes 5 notes

up
3
Amr Mostafa
12 years ago
This function currently terminates execution as well, which may be undesirable. See: http://bugs.php.net/bug.php?id=49513
up
0
Anonymous
13 years ago
If you use Adobe Flex, Flash or AIR as SOAP client and are unable to get the error message in case of a soap fault, upgrade to PHP 5.2.6.

Details in:
http://bugs.php.net/bug.php?id=43507
up
-3
christian at cmjdesign dot dk
9 years ago
hi,
to control the fault output one may do the following

/**
* mySoapServer class
*/
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);
    }
}

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

that how i did this,
hope iot can help some one.
up
-4
dub357 at gmail dot com
10 years ago
This function also sends a 500 response code back to the client with the request.
This was causing issues with an Apache Axis 1.2 client I had so I instead implemented by own fault handling:

<?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>");
?>
up
-6
brian dot reynolds at risaris dot com
10 years ago
Example Usage:

return new SoapFault( "Client", "foo or bar must be supplied");

SOAP Fault Codes

VersionMismatch: Found an invalid namespace for the SOAP Envelope element
MustUnderstand    : An immediate child element of the Header element, with the mustUnderstand attribute set to "1", was not understood
Client: The message was incorrectly formed or contained incorrect information
Server: There was a problem with the server so the message could not proceed

官方地址:https://www.php.net/manual/en/soapserver.fault.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3