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
SoapFault sirve para enviar errores SOAP desde
PHP.faultcode, faultstring,
faultactor y detail son
los elementos estándar SOAP.
faultcodeEl código de error de SoapFault.
faultstringEl mensaje de error de SoapFault.
faultactorUna cadena que identifica al actor que causó el error.
detail
faultnamePuede 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.
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
?>