SlideShare a Scribd company logo
7
Most read
17
Most read
18
Most read
ERROR REPORTING
BY: IQRA BALOCH
What is error?
• An error is a type of mistake. We can say an error is a condition of
having incorrect or false knowledge or an error is defined as an
unexpected, invalid program state from which it is impossible to
recover.
• Error can also be defined as “a deviation from accuracy or
correctness”. A “mistake” is an error caused by fault: the fault being
misjudgment, carelessness or forgetfulness. An error message with
filename, like number and a message describing the error is sent to
be the browser.
Types of error
There are 12 unique error types, which can
be grouped into 3 main categories:
• Informational (Notices)
• Actionable (Warnings)
• Fatal (Runtime)
Informational Errors
• 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 Errors
• 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 Errors
• Something so terrible has happened during 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.
Identifying Errors
notice
warning
fatal
Enabling errors
• display_errors = On
• 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 settings
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.
1. Set error reporting settings
<?php
// Turn off all error reporting
error_reporting(0);
// 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
error_reporting(E_ALL);
?>
1. Set error reporting settings
• 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 Errors
• 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 error reporting setting.
2. Suppressing Errors
• 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.
3. Custom Error Handler
• Custom function must be capable of accepting a minimum of two
mandatory arguments:
o Error type
o Message
• and up to three additional arguments:
o File name
o Line number
o Context
• These arguments are then used to create an error page that is
friendlier and more informative than PHP's standard one-line error
message
3. Custom Error Handler
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;
}
3. Custom Error Handler
• The function then needs to be registered as your custom error
handler:
set_error_handler(‘err_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:
set_error_handler(‘err_handler’,
E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR);
4. Pulling the Trigger
• PHP allows you to use its built-in error handling system to raise your
own custom errors as well.
• 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 E_USER_ERROR.
• When these errors are triggered, PHP's built-in handler will
automatically wake up to handle them.
4. Pulling the Trigger
$db = @mysql_connect($h,$u,$p);
if (!$db) {
trigger_error(‘blah’,E_USER_ERROR);
}
Review
• Various different error types exist in PHP.
• The error handling system is highly flexible, and your own error
handling methods can be developed.

More Related Content

PPTX
Error handling
PPTX
PHP-MySQL Database Connectivity Using XAMPP Server
PDF
Nodejs presentation
PPT
PHP - Introduction to PHP Error Handling
PPTX
JavaScript Promises
PPTX
Introduction to Angularjs
PPT
Introduction to Javascript
PPTX
Introduction to php
Error handling
PHP-MySQL Database Connectivity Using XAMPP Server
Nodejs presentation
PHP - Introduction to PHP Error Handling
JavaScript Promises
Introduction to Angularjs
Introduction to Javascript
Introduction to php

What's hot (20)

PPTX
Java script
PPT
Java Script ppt
PPT
Oops concepts in php
ODP
Datatype in JavaScript
PPTX
Unit 1-uses for scripting languages,web scripting
PPSX
Javascript variables and datatypes
PDF
Basics of JavaScript
PPTX
Laravel ppt
PPT
JavaScript & Dom Manipulation
PDF
Xml parsing
PPTX
Html5 semantics
PPTX
Web Development
PPTX
Express JS
PPTX
Java packages
PPTX
Javascript
PDF
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
PPTX
Web services - A Practical Approach
PDF
Angular - Chapter 4 - Data and Event Handling
DOCX
QWeb Report in odoo
PDF
Html,javascript & css
Java script
Java Script ppt
Oops concepts in php
Datatype in JavaScript
Unit 1-uses for scripting languages,web scripting
Javascript variables and datatypes
Basics of JavaScript
Laravel ppt
JavaScript & Dom Manipulation
Xml parsing
Html5 semantics
Web Development
Express JS
Java packages
Javascript
Angular Directives | Angular 2 Custom Directives | Angular Tutorial | Angular...
Web services - A Practical Approach
Angular - Chapter 4 - Data and Event Handling
QWeb Report in odoo
Html,javascript & css
Ad

Similar to Error reporting in php (20)

PDF
Error Handling In PHP with all Try catch anf various runtime errors
PPTX
lecture 15.pptx
PPT
Php Error Handling
PDF
Introduction to php exception and error management
PDF
Module-4_WTA_PHP Class & Error Handling
PPTX
EDD (Error Driven Development)
PDF
Error handling and debugging
PDF
Sending emails through PHP
PDF
Php exceptions
PDF
TDC 2015 - POA - Trilha PHP - Shit Happens
PPT
Error management
PDF
Object Oriented PHP - PART-2
DOC
Error Handling in Compiler Design.doctyp
DOC
Error Handling in Compiler Design.What a
DOC
Error Handling in Compiler Design.typeso
PPTX
Debugging
PDF
Session10-PHP Misconfiguration
PPT
ASP.NET 05 - Exception Handling And Validation Controls
PPTX
Error handling and debugging in vb
PDF
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
Error Handling In PHP with all Try catch anf various runtime errors
lecture 15.pptx
Php Error Handling
Introduction to php exception and error management
Module-4_WTA_PHP Class & Error Handling
EDD (Error Driven Development)
Error handling and debugging
Sending emails through PHP
Php exceptions
TDC 2015 - POA - Trilha PHP - Shit Happens
Error management
Object Oriented PHP - PART-2
Error Handling in Compiler Design.doctyp
Error Handling in Compiler Design.What a
Error Handling in Compiler Design.typeso
Debugging
Session10-PHP Misconfiguration
ASP.NET 05 - Exception Handling And Validation Controls
Error handling and debugging in vb
VISUAL_BASIC_LECTURE_NOTE_A_Z_MADE_EASY.pdf
Ad

More from Mudasir Syed (20)

PPT
Cookies in php lecture 2
PPT
Cookies in php lecture 1
PPTX
PPT
Reporting using FPDF
PPT
Oop in php lecture 2
PPT
Oop in php lecture 2
PPT
Filing system in PHP
PPT
Time manipulation lecture 2
PPT
Time manipulation lecture 1
PPT
Php Mysql
PPT
Adminstrating Through PHPMyAdmin
PPT
Sql select
PPT
PHP mysql Sql
PPT
PHP mysql Mysql joins
PPTX
PHP mysql Introduction database
PPT
PHP mysql Installing my sql 5.1
PPT
PHP mysql Er diagram
PPT
PHP mysql Database normalizatin
PPT
PHP mysql Aggregate functions
PPT
Form validation with built in functions
Cookies in php lecture 2
Cookies in php lecture 1
Reporting using FPDF
Oop in php lecture 2
Oop in php lecture 2
Filing system in PHP
Time manipulation lecture 2
Time manipulation lecture 1
Php Mysql
Adminstrating Through PHPMyAdmin
Sql select
PHP mysql Sql
PHP mysql Mysql joins
PHP mysql Introduction database
PHP mysql Installing my sql 5.1
PHP mysql Er diagram
PHP mysql Database normalizatin
PHP mysql Aggregate functions
Form validation with built in functions

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Business Ethics Teaching Materials for college
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
Classroom Observation Tools for Teachers
PPTX
Institutional Correction lecture only . . .
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Cell Structure & Organelles in detailed.
PDF
Basic Mud Logging Guide for educational purpose
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Insiders guide to clinical Medicine.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Final Presentation General Medicine 03-08-2024.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Business Ethics Teaching Materials for college
human mycosis Human fungal infections are called human mycosis..pptx
Cell Types and Its function , kingdom of life
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
RMMM.pdf make it easy to upload and study
Classroom Observation Tools for Teachers
Institutional Correction lecture only . . .
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Cell Structure & Organelles in detailed.
Basic Mud Logging Guide for educational purpose
Module 4: Burden of Disease Tutorial Slides S2 2025
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Insiders guide to clinical Medicine.pdf

Error reporting in php

  • 2. What is error? • An error is a type of mistake. We can say an error is a condition of having incorrect or false knowledge or an error is defined as an unexpected, invalid program state from which it is impossible to recover. • Error can also be defined as “a deviation from accuracy or correctness”. A “mistake” is an error caused by fault: the fault being misjudgment, carelessness or forgetfulness. An error message with filename, like number and a message describing the error is sent to be the browser.
  • 3. Types of error There are 12 unique error types, which can be grouped into 3 main categories: • Informational (Notices) • Actionable (Warnings) • Fatal (Runtime)
  • 4. Informational Errors • 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.
  • 5. Actionable Errors • 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.
  • 6. Fatal Errors • Something so terrible has happened during 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.
  • 8. Enabling errors • display_errors = On • error_reporting = ~E_ALL
  • 9. 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..
  • 10. 1. Set error reporting settings 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.
  • 11. 1. Set error reporting settings <?php // Turn off all error reporting error_reporting(0); // 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 error_reporting(E_ALL); ?>
  • 12. 1. Set error reporting settings • 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!
  • 13. 2. Suppressing Errors • 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 error reporting setting.
  • 14. 2. Suppressing Errors • 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.
  • 15. 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.
  • 16. 3. Custom Error Handler • Custom function must be capable of accepting a minimum of two mandatory arguments: o Error type o Message • and up to three additional arguments: o File name o Line number o Context • These arguments are then used to create an error page that is friendlier and more informative than PHP's standard one-line error message
  • 17. 3. Custom Error Handler 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; }
  • 18. 3. Custom Error Handler • The function then needs to be registered as your custom error handler: set_error_handler(‘err_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: set_error_handler(‘err_handler’, E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR);
  • 19. 4. Pulling the Trigger • PHP allows you to use its built-in error handling system to raise your own custom errors as well. • 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 E_USER_ERROR. • When these errors are triggered, PHP's built-in handler will automatically wake up to handle them.
  • 20. 4. Pulling the Trigger $db = @mysql_connect($h,$u,$p); if (!$db) { trigger_error(‘blah’,E_USER_ERROR); }
  • 21. Review • Various different error types exist in PHP. • The error handling system is highly flexible, and your own error handling methods can be developed.