PHP error_get_last() function

Example

Return the last error occurred:

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

The output of the above code is similar to this:

Array
 (
     [type] => 8
     [message] => Undefined variable: test
     [file] => C:\webfolder\test.php
     [line] => 2
 )

Definition and Usage

The error_get_last() function returns the last error that occurred (in the form of an associative array).

The associative array contains four keys:

  • [type] - Description of the error type
  • [message] - Description of the error message
  • [file] - Description of the file where the error occurred
  • [line] - Description of the line number where the error occurred

Syntax

error_get_last();

Technical Details

Return Value:

It returns an associative array describing the information of the last error, with the "type", "message", "file", and "line" of the error as the keys of the array.

If the error is caused by a PHP built-in function, "message" will start with the name of the function.

If there are no errors, it will return NULL.

PHP Version: 5.2+