2

I'd like for PHP to still send it's minor and fatal errors to the error log but not display it to the user. I thought at first I could use error_reporting(0); to suppress all error messages, period, but that's not really ideal. I know I could also put everything inside a try-catch but that's not really ideal either. Is there anything more automatic for regular errors like there are for fatal errors (e.g. register_shutdown_function())?

Speaking of fatal errors, I tried catching them using register_shutdown_function() as suggested in this SO answer. When I did it this way the fatal error was caught but error_get_last(); is always empty. I also tried making use of debug_backtrace(); to catch the error message. It does contain the info I want about fatal errors but it appears to have the undesired side effect of actually printing that info out to the user, the very situation I am trying to avoid.

Are there any other ways to do what I'm trying to do here and/or ways I can do this (log the error messages to the console but not to the user) using the methods I have described above? Thank you.

1

1 Answer 1

3

Set display_errors=0 and log_errors=1 in php.ini.

This should be the default for any production server.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh geez, you're right, I'll have to talk to the admin that set up that app server and ask them why php.ini isn't set up that way on production. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.