Home >Backend Development >PHP Tutorial >error_get_last() function in PHP

error_get_last() function in PHP

WBOY
WBOYforward
2023-08-27 09:21:071487browse

error_get_last() function in PHP

error_get_last() function gets the last error that occurred in the form of 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 p>

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

Syntax

error_get_last()

Parameters

  • NA

Return

error_get_last() function returns an associative array describing the keys "type", " message", "file" and "line". If an error has not occurred, NULL is returned.

Example

The following is an example -

Real-time demonstration

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

Output

The following is the output. Here we are showing error in 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

The above is the detailed content of error_get_last() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete