Elgg  Version 3.0
ErrorHandler.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Application;
4 
6 use Elgg\Loggable;
7 use Exception;
9 
15 class ErrorHandler {
16 
17  use Loggable;
18 
41  public function __invoke($errno, $errmsg, $filename, $linenum, $vars) {
42  $error = date("Y-m-d H:i:s (T)") . ": \"$errmsg\" in file $filename (line $linenum)";
43 
44  switch ($errno) {
45  case E_USER_ERROR:
46  $this->log(LogLevel::ERROR, "PHP ERROR: $error");
47 
49  Application::$_instance->_services->systemMessages->addErrorMessage("ERROR: $error");
50  }
51 
52  // Since this is a fatal error, we want to stop any further execution but do so gracefully.
53  throw new Exception($error);
54 
55  case E_WARNING :
56  case E_USER_WARNING :
57  case E_RECOVERABLE_ERROR: // (e.g. type hint violation)
58 
59  // check if the error wasn't suppressed by the error control operator (@)
60  if (error_reporting()) {
61  $this->log(LogLevel::WARNING, "PHP: $error");
62  }
63  break;
64 
65  default:
66  $this->log(LogLevel::NOTICE, "PHP NOTICE: $error");
67  break;
68  }
69 
70  return true;
71  }
72 }
static $_instance
Reference to the loaded Application.
Definition: Application.php:75
__invoke($errno, $errmsg, $filename, $linenum, $vars)
Intercepts catchable PHP errors.
static isCoreLoaded()
Are Elgg&#39;s global functions loaded?
trait Loggable
Enables adding a logger.
Definition: Loggable.php:12
$error
Bad request error.
Definition: 400.php:6
Handle system and PHP errors.
log($level, $message, array $context=[])
Log a message.
Definition: Loggable.php:55
$vars['type']
Definition: save.php:11
$filename
elgg ajax ERROR
Definition: ajax.js:33