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 — Construtor SoapFault
$code,$string,$actor = null,$details = null,$name = null,$headerFault = null
Esta classe é usada para enviar respostas de falha SOAP do manipulador PHP.
faultcode, faultstring,
faultactor e detail são
elementos padrões de uma falha SOAP.
faultcodeO código de erro do SoapFault.
faultstringA mensagem de erro do SoapFault.
faultactorUma string que identifica o ator que causou o erro.
detailMais detalhes sobre a causa do erro.
faultnamePode ser usado para selecionar a codificação de falha adequada do WSDL.
headerfaultPode ser usado durante a manipulação do cabeçalho SOAP para relatar um erro no cabeçalho de resposta.
Exemplo #1 Alguns exemplos
<?php
function test($x)
{
return new SoapFault("Server", "Some error message");
}
$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->addFunction("test");
$server->handle();
?>É possível usar o mecanismo de exceção PHP para lançar uma falha SOAP.
Exemplo #2 Alguns exemplos
<?php
function test($x)
{
throw new SoapFault("Server", "Some error message");
}
$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
?>