开发者

Is there a way to catch Fatal error in PHP? [duplicate]

开发者 https://www.devze.com 2022-12-28 02:42 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: H开发者_Go百科ow do I catch a PHP Fatal Error
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

H开发者_Go百科ow do I catch a PHP Fatal Error

I have this line of PHP code:

thisFunctionDoesNotExist();

And it stops script execution with:

Fatal error: Call to undefined function

I tried using set_error_handler and it does help for warning type of errors. But not for fatal errors. As I understand it from various threads on internet it should be possible to handle by set_error_handler, but I cannot make it work.

Can you please post working example?

Note: The code above is only an example. I don't need to detect that function exists. I am setting up general application error catcher.


Fatal errors cannot be caught.

Although not an answer to your question; if you have reasons to believe that function might not be around in all cases, check with function_exists();


http://php.net/manual/en/function.function-exists.php

$functionExists = function_exists("thisFunctionDoesNotExist");

iF($functionExists)
    thisFunctionDoesNotExist();
else
    die("failure");

Takes a string which is your function and returns true or false

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号