The first Parameter of the constructor, the faultcode, of SoapFault must be a string. Otherwise it will lead to an error.
<?php
throw new SoapFault(1, "Error message!"); // wrong
throw new SoapFault("1", "Error message!"); // right
?>(PHP 5, PHP 7, PHP 8)
SoapFault::__construct — Constructor de SoapFault
$code,$string,$actor = null,$details = null,$name = null,$headerFault = null,$lang = ""
SoapFault sirve para enviar errores SOAP desde
PHP.code, string,
actor y details son
los elementos estándar SOAP.
codeEl código de error de SoapFault.
stringEl mensaje de error de SoapFault.
actorUna cadena que identifica al actor que causó el error.
details
namePuede ser utilizado para seleccionar la codificación adecuada desde WSDL.
headerFaultPuede ser utilizado durante la gestión del encabezado SOAP para reportar un error en el encabezado de respuesta.
lang| Versión | Descripción |
|---|---|
| 8.5.0 |
Se ha añadido el parámetro opcional lang
para cumplir con la especificación SOAP 1.2.
|
Ejemplo #1 Algunos ejemplos con SoapFault
<?php
function test($x)
{
return new SoapFault("Server", "Un mensaje de error");
}
$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->addFunction("test");
$server->handle();
?>Es posible utilizar el mecanismo de excepciones de PHP para lanzar excepciones SoapFault.
Ejemplo #2 Emisión de excepciones SoapFault
<?php
function test($x)
{
throw new SoapFault("Server", "Un mensaje de error");
}
$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->addFunction("test");
$server->handle();
?>
The first Parameter of the constructor, the faultcode, of SoapFault must be a string. Otherwise it will lead to an error.
<?php
throw new SoapFault(1, "Error message!"); // wrong
throw new SoapFault("1", "Error message!"); // right
?>