What is custom error handler in PHP

In this article I am going to explain about custom error handler in PHP.
  • 2016

Custom error handler in PHP

You can create your own custom error handler function for handling errors in PHP. In this handler two parameter must be defined.

Syntax of custom error handler

error_function(error_level, error_message, error_file,  error_line,  error_context);


Parameters in custom error handler

There are following parameters in PHP custom error handler:
 

Parameter Description
error_level Requird, It specifies the error report level for user defined error.
error_message Required, It specifies the error message for user defined error.
error_file Optional, It specifies the filename in which error fired.
error_line Optional, It specifies the line number in which error fired.
error_context Optional, It specifies an array containing every variable, and their values in use when error is fired.

Example of  custom error handler

<html>

<body>

<?php

function customErrorHandler($errlevel, $errmess)

  {

  echo "<b>Error:</b> [$errlevel] $errmess";

  }

set_error_handler("customErrorHandler");

echo"The error is :"."</br>";

echo($val);

?>

</body>

</head>


Output:

custom handler.jpg

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2019 DotNetHeaven. All rights reserved.