Error Reporting in PHP

What is error reporting

An error is a type of mistake. We can say an error is a condition of having an incorrect or false knowledge or an error is defined as an unexpected, invalid program state from which it is impossible
to recover.

PHP Error can also be defined as “a deviation from accuracy or correctness”. A “mistake” is an error caused by a fault: the fault being misjudgment, carelessness or forgetfulness. An error message with the filename, Like number and a message describing the error, is sent to be the browser. 

Error Reporting in PHP

Types of PHP Error Reporting

There are 12 unique error types, which can be grouped into 3 main categories:
•Informational (Notices)
•Actionable (Warnings)
•Fatal (Runtime)

Informational Error

The harmless problem, non-critical errors that PHP encounters while executing a script. In the notice error execution of the script does not stop.

 e.g. use of an undefined variable, defining a string without quotes, Referencing non-existent array 
keys etc.

Actionable Error

Indicate that something clearly wrong has happened and that action should be taken.
e.g. file not present, database not available, missing function arguments, etc.

Fatal Error 

Something so terrible has happened during the execution of your script that further processing simply cannot continue.
e.g. parsing error, calling an undefined function, require() when the file does not exist etc. 

  how to create calculator in PHP

Identifying Error 


Enabling Error 

•php display_errors = On

•php error_reporting = ~E_ALL

Customizing Error Handling

•Generally, how PHP handles errors is defined by various constants in the installation (php.ini).
•There are several things you can control in your scripts, however. 

1. Set Error_Reporting Setting

PHP error_reporting($level)
This function can be used to control which errors are displayed, and which are simply ignored. 
The effect only lasts for the duration of the execution of your script. 


// Turn off all error reporting
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
error_reporting(E_ALL ^ E_NOTICE);
// Report ALL PHP errors

Hiding errors is NOT a solution to a problem.

•It is useful, however, to hide any errors produced on a live server.
While developing and debugging code, displaying all errors is highly recommended

2. Suppressing Error 

The special @ operator can be used to suppress function errors.
•Any error produced by the function is suppressed and not displayed by PHP regardless of the PHP error reporting setting

Error suppression is NOT a solution to a problem.
•It can be useful to locally define your own error handling mechanisms.
•If you suppress any errors, you must check for them yourself elsewhere.

3. Custom Error Handler 

You can write your own function to handle PHP errors in any way you want.
You simply need to write a function with appropriate inputs, then register it in your script as the error handler.
Function called set_error_handler(), it allows to divert all PHP errors to a custom function that are 
defined, instead of sending them to the default handler.
•Custom function must be capable of accepting a minimum of two mandatory arguments:
1.Error type
•and up to three additional arguments:
1.File name
2.Line number
• These arguments are then used to create an error page that is friendlier and more informative than PHP's standard one-line error message

function err_handler(
$errcode,$errmsg,$file,$lineno, $context) {
echo ‘An error has occurred!<br />’;
echo “file: $file<br />”;
echo “line: $lineno<br />”;
echo “Problem: $errmsg”;
echo “Variable State: $contexts”;
return true;

•The function then needs to be registered as your custom error handler:
•You can ‘mask’ the custom error handler so it only receives certain types of error. e.g. to register a custom handler just for user triggered errors:

Ajax in PHP

4.Pulling the Trigger 

PHP allows you to use its built-in error handling system to raise your own custom errors as

This is accomplished via a function named trigger_error(), which allows you to raise any of

the three error types reserved for users: E_USER_NOTICE, E_USER_WARNING and


When these errors are triggered, PHP's built-in handler will automatically wake up to handle them.

$db = @mysql_connect($h,$u,$p);
if (!$db) {


•Various different error types exist in PHP.
•The error handling system is highly flexible, and your own error handling methods can 
be developed.



Blogging,8,How to,21,Make Money,9,SEO,14,Tricks & Tips,1,Web Designing,10,Web Development,6,
Weblog Tricks - Learn Everything About Web : Error Reporting in PHP
Error Reporting in PHP
Error Reporting in PHP ini display_errors not working hide in Php, identify warning fatal, and also step by step describe trigger
Weblog Tricks - Learn Everything About Web
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy