views:

37

answers:

1

I have the following PHP code on a web page:

$wsdl_url = "someURL?wsdl";
try {
    $client = new SoapClient($wsdl_url, array('login' => 'mylogin','password' => 'mypassword'));
    $client->myWebMethod();  // <-- problem call
} catch (Exception $e) {
    echo "none";
}

It's a basic call to a web service. The problem is that when an error is thrown on the line $client->myWebMethod(), echo "none" is not printed. In fact, nothing in the catch block runs. Hence, I don't think the exception is being caught.

A fatal error is displayed on the web page.

Question: Any ideas on why this is happening? I expected all exceptions to be caught and handled with this code. But what I'm getting is that the fatal error is being displayed on the page. Maybe web services are handled differently?

EDIT: the error is that it's missing a bunch of required parameters. if I add the parameters the call works fine. I am purposely omitting the parameters to get the error, so i would know how to handle it.

The error is something like: Fatal error: SOAP-ERROR: Object hasn't 'myparameter1'

Thanks in advance.

+1  A: 

Unfortunately, this is not a catchable error.

However, you can check if the soap extension is loaded before trying to instantiate it by calling get_loaded_extensions with something along the lines of:

if  (in_array('soap', get_loaded_extensions())) {
    // it's loaded!
}
webbiedave
To clarify @webbiedave's answer, PHP has both `errors` and `exceptions`. You can handle errors with [an error handler](http://www.php.net/manual/en/function.set-error-handler.php).
Josh
Thanks for the comments, I made an edition and noted the error I was getting. the soap extension is working fine.
kenzaraque