(PHP 5, PHP 7, PHP 8)

SoapServer::addFunctionAdiciona uma ou mais funções para lidar com solicitações SOAP


public SoapServer::addFunction(array|string|int $functions): void

Exporta uma ou mais funções para clientes remotos



Para exportar uma função, passe o nome da função para este parâmetro como uma string.

Para exportar diversas funções, passe um array de nomes de funções.

Para exportar todas as funções, passe uma constante especial SOAP_FUNCTIONS_ALL.


functions devem receber todos os argumentos de entrada na mesma ordem definida no arquivo WSDL (eles não devem receber nenhum parâmetro de saída como argumentos) e retornar um ou mais valores. Para retornar vários valores eles devem retornar um array com parâmetros de saída nomeados.

Valor Retornado

Nenhum valor é retornado.


Exemplo #1 Exemplo de SoapServer::addFunction()


function echoString($inputString)


echoTwoStrings($inputString1, $inputString2)
return array(
"outputString1" => $inputString1,
"outputString2" => $inputString2);
$server->addFunction(array("echoString", "echoTwoStrings"));



Veja Também

add a note

User Contributed Notes 3 notes

dotpointer at gmail dot com
16 years ago
Be careful with SOAP_FUNCTIONS_ALL, as it adds ALL availiable PHP functions to your server.

This can be a potential security threat, imagine clients doing this:

echo $client->file_get_contents("c:\\my files\\my_passwords.doc");

And voila, they have the contents of your file my_passwords.doc.
Nathan O'Sullivan
19 years ago
You may be left wondering, as I was, how to return a complex type - consider the following WSDL snippets, for a method called Login:

<xs:element name="Login">
<xs:element minOccurs="0" maxOccurs="1" name="username" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="password" type="xs:string" />

<xs:complexType name="UserInfo">
<xs:element minOccurs="0" maxOccurs="1" name="Id" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Name" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Nickname" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Email" type="xs:string" />

<xs:element name="LoginResponse">
<xs:element minOccurs="0" maxOccurs="1" name="LoginResult" type="s0:UserInfo" />

Here's a working Login function that I've added with add SoapServer::addFunction

function Login($username, $password)
return array("LoginResult", array("Id"=>1, "Name"=>"Nathan", "Nickname"=>"Nathan", "Email"=>"email address") );

The UserInfo complextype is represented by the inner array. The outer array has just one element, "LoginResult". The LogineResponse element seems to be treated as a one-member array by PHP.
Evan Borgstrom
17 years ago
In response to comment by Nathan O'Sullivan about returning (or passing) a complex type, you can also use the stdClass() object.

Assume you define a complex type like so:

<xsd:complexType name="TestType">
<xsd:element name="A" type="xsd:string" />
<xsd:element name="B" type="xsd:int" />
<xsd:element name="C" type="xsd:boolean" />

To use an object in place of an array you can do:

$test = new stdClass();
$test->A = "test string";
$test->B = 45;
$test->C = false;

$result = $client->Test($test);
To Top