Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday 25 July 2017

Error Reporting in PHP

Error Reporting in PHP :-

If you are using PHP script for your website or you are developing form based application, then you should know about Error-Reporting in php and anable it on your end, in order to catch all error relating issue. Sometime developers are going confused if they run their script and the output of the script is not what they expect, also they do not get any error on the output and that's why it is necessary to catch the error at the development stage of the project so we can handle all the errors.
So here i am going to tell you that how can we catch all the errors in php.


 //1. Report all errors in php
error_reporting(E_ALL);

//2. Reporting simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

//3. Reporting E_NOTICE can be good too (to report uninitialised variables or catch the variables //name missplleings...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

//4. Report all errors except E_NOTICE
error_reporting(E_ALL ! ~E_NOTICE);

//5. Report all PHP errors
error_reporting(-1);

//6. You can show all errors in php by add this line( this line should be at the top of your php script) in //your php file
ini_set('error_reporting', E_ALL);


   Note :: For syntax errors, you need to enable error display in the php.ini. By default these are turned off because you don't want a "customer" seeing the error messages. Check this page in the PHP documentation for information on the 2 directives: error_reporting and display_errors. display_errors is probably the one you want to change. If you can't modify the php.ini, you can also add the following lines to an .htaccess file:

php_flag  display_errors        on
php_value error_reporting       2039

You may want to consider using the value of E_ALL  for your version of PHP for error_reporting to get all of the errors.

Three other items you should know :
(1) You can check the error log file as it will have all of the errors (unless logging has been disabled).

(2) Adding the following 2 lines will help you debug errors that are not syntax errors:
error_reporting(-1);
ini_set('display_errors', 'On');

(3) Another option is to use an editor that checks for errors when you type, such as PhpEd. PhpEd also comes with a debugger which can provide more detailed information. (The PhpEd debugger is very similar to xdebug and integrates directly into the editor so you use 1 program to do everything.)
       

No comments:

Post a Comment