Skip to content
Related Articles

Related Articles

How to get the last occurred error using PHP ?

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 27 Jan, 2021
Improve Article
Save Article

It is very easy to get information about the last error that occurred in PHP using error_get_last() function. We can get very detailed information about the error such as, file and line number at which the error occurred.



Return value:

 (associative array | NULL)

The associative array returned above contains data as follows:

  • type : Type of error (error code)
  • message : Error Message
  • file : Path of file in which error occurred
  • line : Line number at error occurred in above file

PHP code:


  echo $var; // This line will throw error
  $error_info = error_get_last();
  echo '<br/>';
  print_r ($error_info['type']);
  echo '<br/>';
  print_r ($error_info['message']);
  echo '<br/>';
  print_r ($error_info['file']);
  echo '<br/>';
  print_r ($error_info['line']);


Array ( 
    [type] => 8 
    [message] => Undefined variable: var 
    [file] => /home/nzH0BV/prog.php 
    [line] => 2 
Undefined variable: var
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!