PHP Function Reference

PHP error_get_last() Function



The PHP error_get_last() function is used to get the information about the last occurred error.

Syntax

error_get_last()

Parameters

No parameter is required.

Return Value

Returns an associative array describing the last error with following keys:

  • "type" - The error type
  • "message" - The error message
  • "file" - The file where the error occurred
  • "line" - The line number where the error occurred

If the error has been caused by a PHP internal function then the "message" begins with its name. Returns null if there hasn't been an error yet.

Example: error_get_last() example

The example below shows the usage of error_get_last() function.

<?php
//using undefined variable
echo $a;

//getting last occurred error
//and displaying it
print_r(error_get_last());
?>

The output of the above code will be:

Array
(
    [type] => 2
    [message] => Undefined variable $a
    [file] => Main.php
    [line] => 3
)

PHP Warning:  Undefined variable $a in Main.php on line 3

❮ PHP Error Handling Reference