php8.5
Home/ Manual/ yar / yar_client/ Yar_Client::call

Yar_Client::call

PHP function Edit on GitHub ✎

(PECL yar >= 1.0.0)

Call a remote service

Description

Yar_Client::call(string $method, array $arguments): mixed

Issues an RPC call to the remote method method. This is exactly what happens when a non-existent method is invoked on a Yar_Client object (via PHP's __call magic method); Yar_Client::call only exists so that remote methods literally named call or __call can still be reached.

Parameters

method

The name of the remote service method.

arguments

The list of arguments passed to the remote method.

Return Values

Returns the return value of the remote service method.

Errors/Exceptions

When the remote method does not exist on the server, or is not public, the client throws a Yar_Client_Exception with the code YAR_ERR_REQUEST. See Yar_Client_Exception for the other client-side failures and their exception classes.

Examples

Yar_Client::call example

php
<?php
$client = new Yar_Client("http://api.example.com/operator.php");

/* The usual way: invoke the remote method as if it were local.
 * This is translated into call("add", array(1, 2)) behind the scenes. */
var_dump($client->add(1, 2));

/* Equivalent: call the method explicitly by name */
var_dump($client->call("add", array(1, 2)));

/* Needed only when the remote service literally exposes a method
 * named call (or __call), which the magic __call cannot reach */
var_dump($client->call("call", array($some_argument)));
?>

The above example will output something similar to:

output
int(3)
int(3)
...

See Also

  • Yar_Client::setOpt

Source: reference/yar/yar_client/call.xml · from the official PHP manual (php/doc-en)