CakeFest 2025 Madrid: The Official CakePHP Conference

The SoapFault class

(PHP 5, PHP 7, PHP 8)

Introduction

Represents a SOAP fault.

Class synopsis

class SoapFault extends Exception {
/* Properties */
public ?string $faultcode = null;
public ?string $faultcodens = null;
public ?string $faultactor = null;
public mixed $detail = null;
public ?string $_name = null;
public mixed $headerfault = null;
/* Inherited properties */
protected string $message = "";
private string $string = "";
protected int $code;
protected string $file = "";
protected int $line;
private array $trace = [];
private ?Throwable $previous = null;
/* Methods */
public __construct(
    array|string|null $code,
    string $string,
    ?string $actor = null,
    mixed $details = null,
    ?string $name = null,
    mixed $headerFault = null
)
public __toString(): string
/* Inherited methods */
final public Exception::getCode(): int
final public Exception::getFile(): string
final public Exception::getLine(): int
final public Exception::getTrace(): array
}

Properties

_name

detail

faultactor

faultcode

faultcodens

faultstring

headerfault

Table of Contents

add a note

User Contributed Notes 3 notes

up
43
dmitry dot koterov at gmail dot com
15 years ago
You may use undocumented and invisible property $e->faultcode to access string version of $code. Because standard $e->getCode() does not work:

$e = new SoapFault("test", "msg");
var_dump($e->getCode()); // prints "0"
var_dump($e->faultcode); // prints "test"
?>

Also you may use namespaced fault codes:

$e = new SoapFault(array("namespace", "test"), "msg");
?>

- see ext/soap/soap.php, PHP_METHOD(SoapFault, SoapFault). To access the namespace, use $e->faultcodens
up
11
chris AT cmbuckley DOT co DOT uk
15 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:

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
4
fbernoldi at gmail dot com
12 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)










WSDL messages:





WSDL port type:






....


You have to specify the response in the detail parameter as an array corresponding the tag names.

PHP Code:


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:

http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://mynamespace">


SOAP-ENV:Server
example fault string


Explanation 1
Explanation 2






I Hope it helps,
Federico.
To Top