Client-Side PHP Mapping for Operations
Mapping for Operations
As we saw in the Client-Side PHP Mapping for Interfaces, for each operation on an interface, a proxy object narrowed to that interface’s type supports a method with the same name. To invoke an operation, you call it via the proxy. For example, here is our definition from the greeter example:
module VisitorCenter
{
interface Greeter
{
string greet(string name);
}
}
Given a proxy to an object of type Greeter, the client can invoke the greet operation as follows:
$greeter = VisitorCenter\GreeterPrxHelper::createProxy(
$communicator, 'greeter:tcp -h localhost -p 4061');
$greeting = $greeter->greet('Alice'); // Get name via RPC
Exception Handling
Any operation invocation may throw a runtime exception and, if the operation has an exception specification, may also throw user exceptions. Suppose we have the following simple interface:
exception Tantrum
{
string reason;
}
interface Child
{
void askToCleanUp() throws Tantrum;
}
Slice exceptions are thrown as PHP exceptions, so you can simply enclose one or more operation invocations in a try-catch block:
$child = ... // Get child proxy...
try {
$child->askToCleanUp();
} catch(Tantrum $t) {
echo "The child says: " . $t->reason . "\n";
}