Caio
Caio

Reputation: 3215

Analyze every function I call

I want to analyze the result of each function that I call. If this result is a exception or is false then the script ends. I can do this manually, but it is a big waste of time to call a control function for each new function.

Can I configure PHP to set this error function automatically?

Upvotes: 0

Views: 249

Answers (2)

sakhunzai
sakhunzai

Reputation: 14470

Check the comments , will give you and idea of how to register callbacks .

How do I catch a PHP Fatal Error

Here are some steps I ll suggest :

a) register register_shutdown_function or other callback functions to track your exceptiosn

b) Each function call Should throw an exception when there is error

c) call_back function catches the exception

d) echo custom output

check my comment on above reference question

Upvotes: 1

OIS
OIS

Reputation: 10033

You mean the call_user_func and call_user_func_array functions?

function error ($funcName, $funcParameter) {
    try {
        $params = func_get_args();
        unset($params[0]);
        call_user_func_array($funcName, $params) or exit ("Error !");
    }
    catch (exception $e) {
        exit ("Error !");
    }
}

Upvotes: 0

Related Questions