Snippet to display all errors in PHP

In this article I leave you the code to copy and paste on how show errors in php. These snippets that you will find below work perfectly and I use them regularly in my developments.

With the following code snippets you will be able to perform various procedures with php errors:

  • Show by the browser all the errors that appear during the execution of the code. NOTICE type errors such as “undefined index php” or WARNINGS such as “undeclared variable”.
  • Show all errors but in the server log, so that web users don’t see them.
  • Show all errors except warnings and notices, which are errors with which our code can continue to work, although it is advisable to fix them to achieve good code.

Content

  • Show all types of errors in PHP
  • Log of all PHP errors
  • Show all errors except notice in php.ini

Show all types of errors in PHP

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Log of all PHP errors

ini_set('display_errors', 0); //no se muestran por pantalla los errores
ini_set('display_startup_errors', 1);
error_reporting(E_ALL); //se hace log de los errores

Show all errors except notice in php.ini

ini_set('display_errors', 1); //no se muestran por pantalla los errores
ini_set('display_startup_errors', 1);
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);

Leave a Reply