How can we debug a PHP script when display_errors is off and PHP is running in safe mode ?
6 Answers
The best way is to use error_log() http://php.net/manual/en/function.error-log.php And you can set specific handler to that method. Either record it to database, file or simply display the error.
If you want to set handler method you can use: set_error_handler
Comments
If you're in a development environment you should disable safe_mode and enable error_reporting. On a production environment you should probably not do live debugging (since it's live). If you want to track down errors that seem to be only present on the production environment use error_log, or use the logging mechanism of the framework you are using, and check the logs afterwards. This way you won't break the normal operation of your production environment. Some frameworks like symfony provide a separate interface to access your system in another environment (for example accessing index.php has error reporting disabled but frontend_dev.php has not)
If you don't have a separate production and development environment it is high time to separate the two. You can for example install XAMPP or similar to your development PC, where you can do the development and only deploy to the live servers if you have already debugged / tested / etc. your code.