This topic is locked
[SOLVED]

 How to avoid errors when using fgets and simple_xml

8/25/2014 9:49:06 AM
PHPRunner General questions
C
cis2131 author

Can anyone tell me how to get phprunner to ignore php errors, like if a file is not present, or simple_xml fails to connect.
I have tried all the regular things, like putting a @ infront and error_reporting(0) etc., but it still gives me an error.
Claus

Sergey Kornilov admin 8/25/2014

The correct approach is to make sure that your code doesn't produce errors. Ignoring errors is a bad idea in general.

C
cis2131 author 8/25/2014



The correct approach is to make sure that your code doesn't produce errors. Ignoring errors is a bad idea in general.


In my program I load data from a web API that returns data as XML. So I use simplexml to parse it.

But I can't be sure that the API is always listening.
So do you have any suggestion how check if that simplexml request won't return errors before I call it?
Claus

Sergey Kornilov admin 8/26/2014

Claus,
in PHP you can set your own error handler:

http://php.net/manual/en/function.set-error-handler.php
You can set your own error handler right before making that simplexml request.