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 — Constructeur SoapFault
$code,$string,$actor = null,$details = null,$name = null,$headerFault = null
SoapFault sert à envoyer des erreurs SOAP depuis
le PHP.faultcode, faultstring,
faultactor et detail sont
les éléments standards SOAP.
faultcodeLe code erreur de SoapFault.
faultstringLe message d'erreur de SoapFault.
faultactorUne chaîne identifiant l'acteur qui a causé l'erreur.
detail
faultnamePeut être utilisé pour sélectionner l'encodage qui convient depuis WSDL.
headerfaultPeut être utilisé durant la gestion de l'entête SOAP pour rapporter une erreur dans l'en-tête de réponse.
Exemple #1 Quelques exemples avec SoapFault
<?php
function test($x)
{
return new SoapFault("Server", "Un message d'erreur");
}
$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->addFunction("test");
$server->handle();
?>Il est possible d'utiliser le mécanisme des exceptions de PHP pour lancer des exceptions SoapFault.
Exemple #2 Emission d'exceptions SoapFault
<?php
function test($x)
{
throw new SoapFault("Server", "Un message d'erreur");
}
$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
?>