Error and Logging Functions in PHP: PART 3

Introduction

In this article I describe the PHP error and logging functions error_log, trigger_error and user_error. To learn some other error and logging functions, go to:

  1. Error and Logging Functions in PHP: PART 1
     
  2. Error and Logging Functions in PHP: PART 2

PHP  error_log Function

The PHP error_log function sends an error message to the web server's error log or to a file and it returns true on success or false on failure.


Syntax

error_log(error, type,destination,headers)

Parameter in error_log Function

The parameters of the function are:

Parameter Description
error It specifies the error message that should be logged.
type It specifies the error log type.
destination It specifies where to send the error messages.
headers It specifies the extra headers. It is used when the message type parameter is set to 1.

Example

An example of the
function is:

<?
php
$test
=2;

if
($test>1)
{
error_log("An error has been trigged",1,"[email protected]","From: [email protected]");
}
?>

Output

error-log-function-in-php.gif

PHP  trigger_error Function

The PHP trigger_error function creates a user-defined method and it returns FALSE if the wrong error type is specified, otherwise it returns true.

Syntax

trigger_error(errorMessage, errorType)

Parameter in trigger_error Function

The parameters of the function are:

Parameter Description
error_message It specifies the error message.
error_type It specifies the error type of the error message.

Example

An example of the
function is:

<?
php
$var
=0;

if
($var<1)
{

trigger_error
("A error has been occurred.");
}

?>

Output
 

trigger-error-function-in-php.gif

PHP  user_error Function

The PHP user_error function creates user-defined error messages and is also an alias of the trigger_error function.


Syntax
 

user_error(errorMessage, errorType)

Parameter in user_error Function

The parameters of the function are:

Parameter Description
error_message It specifies the error message.
error_type It specifies the error type of the error message.

Example

An example of the
function is:

<?
php
$var
=0;

if
($var<1)
{

user_error
("A error has been occurred.");
}

?>

Output

user-error-function-in-php.gif

Up Next
    Ebook Download
    View all
    Learn
    View all