| Viewed 101 times

PHP how to display errors


PHP how to display errors

PHP
1 Answer
Mohammad Qandeel
Answered
9

Type of PHP error 

there are four types of errors in PHP

  • Parse Error
  • Fatal Error
  • Warning Error
  • Notice Error

How to show all PHP errors

there is more than one way to show error and I will mention them below

Show PHP error via code

using ini_set and error_reporting function 

<?php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
?>

ini_set function will try to override the configuration in the PHP.ini file.

but this method will not show parse errors.

Show PHP errors via PHP.ini file

You'll need to change the PHP.ini to display all errors

Look for display_errors = off   in PHP.ini file  and make it display_errors = on

you can find PHP.ini file in your server by creating a new PHP file and write this script 

<?php phpinfo(); ?>

search for Configuration File and you will see the PHP.ini path

Show PHP error via .htaccess file 

This file located at the root directory of your project 
If you don't have it, you can create a new .htaccess file 

write this configuration on it 

php_flag display_startup_errors on
php_flag display_errors on

don't forget to stop showing any error on the production version of your script