0

I'm getting close to taking a PHP application live and so I know that I need to disable error reporting (to hide errors from users) and instead log the errors.

I found the set_error_handler function in the PHP docs and there is an example shown, but I'm wondering if there is any kind of standard error handler function (to be set as the callback in set_error_handler) or class that is typically used by PHP developers to log errors?

If there isn't a function or class that is considered "standard," would you show your error handling function?

2
  • perishablepress.com/… Commented Jul 19, 2013 at 18:35
  • I understand that you probably don't want an error to display in your software on your server. But please don't try to change the server settings (i.e. ini_set) of other peoples servers. You are better off writing your code to not throw silly errors like notice/warnings and verbosely check values for expected results (i.e. check if is_array before a foreach if there is even a small chance it isn't an array and you "know" it will be...etc). Changing server settings is a quick way to get deleted. Commented Jul 19, 2013 at 18:56

2 Answers 2

2

Your best bet would be to make changes to the php.ini file to turn on-screen error reporting off but error logging on:

ini_set("display_errors", 0);
ini_set("log_errors", 1);
ini_set("error_reporting", E_ALL &~E_DEPRECATED);
ini_set("error_log", "error.log");
Sign up to request clarification or add additional context in comments.

Comments

1

error_log — Send an error message to the defined error handling routines

http://php.net/manual/en/function.error-log.php

http://www.stanford.edu/dept/its/communications/webservices/wiki/index.php/How_to_perform_error_handling_in_PHP

Comments

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.