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