PHP 8.4.0 RC3 available for testing

SoapClient::__call

(PHP 5, PHP 7, PHP 8)

SoapClient::__callRuft eine SOAP-Funktion auf (veraltet)

Beschreibung

public SoapClient::__call(string $name, array $args): mixed

Der Aufruf dieser Methode wird missbilligt. Normalerweise können SOAP-Funktionen als Methoden des SoapClient-Objekts aufgerufen werden; in Situationen wo das nicht möglich ist, oder zusätzliche Optionen benötigt werden, ist SoapClient::__soapCall() zu verwenden.

Parameter-Liste

name

Der Name der aufzurufenden SOAP-Funktion.

args

Ein Array mit den Parametern, die an die Funktion übergeben werden sollen. Dies kann entweder ein geordnetes oder ein assoziatives Array sein. Zu beachten ist, dass die meisten SOAP-Server die Angabe von Parameternamen verlangen, weshalb es in diesem Fall ein assoziatives Array sein muss.

Rückgabewerte

SOAP-Funktionen können einen oder mehrere Werte zurückgeben. Wenn von einer SOAP-Funktion nur ein Wert zurückgegeben wird, ist der Rückgabewert ein Skalar. Wenn mehrere Werte zurückgegeben werden, wird stattdessen ein assoziatives Array von benannten Ausgabeparameter zurückgegeben.

Wenn das SoapClient-Objekt mit der auf false gesetzten Option exceptions erstellt wurde, wird bei einem Fehler ein SoapFault-Objekt zurückgegeben.

add a note

User Contributed Notes 2 notes

up
22
philipp dot gruber at catchoftheday dot com dot au
10 years ago
If you are using a WSDL, the library will strip out anything from your parameters that is not defined in WSDL, without giving you any notice about this.

So if your parameters are not fully matching the WSDL, it will simply send no parameters at all.
This can be a bit hard to debug if you don't have access to the target server.

__soapCall() expects parameters in an array called 'parameters' as opposed to calling the function via it's WSDL name, where it accepts the parameters as a plain array.

I.e. if a function called sendOrder expects a parameter (array) called orderDetails, you can call it like this:

$orderDetails = array(/* your data */);
$soap->sendOrder(array('orderDetails' => $orderDetails));

Which is equivalent to:

$client->__soapCall('sendOrder', array('parameters' => array('orderDetails' => $orderDetails)));

Note the additional 'parameters' key used in __soapCall().
up
7
KRavEN
15 years ago
extend of __call thats adds a retry to handle the occasional 'Could not connect to host' exceptions

<?php
class LocalSoapClient extends SoapClient
{

public function
__call($function_name, $arguments)
{
$result = false;
$max_retries = 5;
$retry_count = 0;

while(!
$result && $retry_count < $max_retries)
{
try
{
$result = parent::__call($function_name, $arguments);
}
catch(
SoapFault $fault)
{
if(
$fault->faultstring != 'Could not connect to host')
{
throw
$fault;
}
}
sleep(1);
$retry_count ++;
}
if(
$retry_count == $max_retries)
{
throw new
SoapFault('Could not connect to host after 5 attempts');
}
return
$result;
}
}
?>
To Top