Computer >> Computer tutorials >  >> Programming >> PHP

error_get_last() function in PHP


The error_get_last() function gets the last error occurred as an associative array.The associative array contains four keys −

  • [type] - Describes the error type

  • [message] - Describes the error message

  • [file] - Describes the file where the error occurred

  • [line] - Describes the line where the error occurred

Syntax

error_get_last()

Parameters

  • NA

Return

The error_get_last() function returns an associative array describing the last error with keys "type", "message", "file" and "line". Returns NULL if there hasn't been an error yet.

Example

The following is an example −

<?php
   echo $res;
   print_r(error_get_last());
?>

Output

The following is the output. Here we are displaying the error in an associative array −

Array
(
   [type] => 8
   [message] => Undefined variable: res
   [file] => /home/cg/root/4127336/main.php
   [line] => 2
)
PHP Notice: Undefined variable: res in /home/cg/root/4127336/main.php on line 2