2

I have this snippet running:

foreach($config as $wsInfo){
  try{
    $soapClient = new SoapClient($wsInfo['url'], 
                                 array('encoding'=>'ISO-8859-1'));

    //  Some more code that I commented out.

  }
  catch(Exception $e){
    echo "EXCEPTION: \n" . $e->getMessage();
    // log it, etc.
  }
}

When I run the program the Web Service URL responds me with an authentication error (which is ok at this point of development).

The extrange behavior I'm noting is that, while I was expecting for this:

$ php scan.php -p=/ -c=config.yml
EXCEPTION: 
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
EXCEPTION: 
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"

It's giving me this:

$ php scan.php -p=/ -c=config.yml
PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
 in /home/me/project/DFPushSOAP.php on line 34
EXCEPTION: 
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
PHP Fatal error:  SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"
 in /home/me/project/DFPushSOAP.php on line 34
EXCEPTION: 
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://webservices.myserver.com/api.asmx?WSDL' : failed to load external entity "http://webservices.myserver.com/api.asmx?WSDL"

Why is a "PHP Fatal error" not killing the program? And why is it escaping the try/catch block?

How can I avoid this?

hakre
  • 193,403
  • 52
  • 435
  • 836
Sebastián Grignoli
  • 32,444
  • 17
  • 71
  • 86

2 Answers2

3

I had the same problem and found a solution at https://bugs.php.net/bug.php?id=47584.

At first you should set exceptions options to force SoapClient to throw Exceptions:

    $soapClient = new SoapClient($wsInfo['url'], array('encoding'=>'ISO-8859-1'
                                                       'exceptions' => true ));

in my case xdebug was forcing to produce a Fatal Error instead of a catchable Exception. So you should try to disable xdebug for the SoapClient creation:

    if(function_exists('xdebug_disable')){ xdebug_disable(); };
    $soapClient = new SoapClient($wsInfo['url'], array('encoding'=>'ISO-8859-1'
                                                       'exceptions' => true ));
    if(function_exists('xdebug_enable')){ xdebug_enable(); };

hope this will help you ^^

Sebastián Grignoli
  • 32,444
  • 17
  • 71
  • 86
DasBaconfist
  • 606
  • 6
  • 14
0

The solution with temporarily disabling xdebug does not work for me (running PHP 7.0.12 / amd64) with enabled xdebug).

The answers the mentioned bug at https://bugs.php.net/bug.php?id=47584 show a solution with an custom temporary error handler. See post from _ [2012-10-03 09:36 UTC] james dot silver at computerminds dot co dot uk_.

As a dirty workaround you can deactivate error_reporting()

$level = error_reporting();
error_reporting(0);
$soapClient = new SoapClient($wsInfo['url'], array(
    'encoding'=>'ISO-8859-1'
    'exceptions' => true )
);
error_reporting($level);

But the custom error handler looks more pleasant. See https://stackoverflow.com/a/12565073/4351778

Community
  • 1
  • 1
prokki
  • 111
  • 3
  • 12