Skip to content

Instantly share code, notes, and snippets.

@devig
Created May 5, 2019 19:40
Show Gist options
  • Save devig/9c3a953782fd38f9d32ad89efed984d3 to your computer and use it in GitHub Desktop.
Save devig/9c3a953782fd38f9d32ad89efed984d3 to your computer and use it in GitHub Desktop.
Не логировать E_NOTICE в opencart
class ControllerStartupError extends Controller {
public function index() {
$this->registry->set('log', new Log($this->config->get('config_error_filename')));
set_error_handler(array($this, 'handler'));
//error_reporting(E_ALL & ~E_NOTICE);
//set_error_handler(array($this, 'handler'),E_ALL & ~E_NOTICE); //E_ERROR | E_WARNING | E_USER_WARNING);//просто игнорировать NOTICE
}
public function handler($code, $message, $file, $line) {
// error suppressed with @
if (error_reporting() === 0) {
return false;
}
switch ($code) {
case E_NOTICE:{
return true;
}
case E_USER_NOTICE:{
$error = 'Notice';
break;
return true;
}
case E_WARNING:
case E_USER_WARNING:
$error = 'Warning';
break;
case E_ERROR:
case E_USER_ERROR:
$error = 'Fatal Error';
break;
default:
$error = 'Unknown';
break;
}
if ($this->config->get('config_error_display')) {
echo '<b>' . $error . '</b>: ' . $message . ' in <b>' . $file . '</b> on line <b>' . $line . '</b>';
}
if ($this->config->get('config_error_log')) {
$this->log->write('PHP ' . $error . ': ' . $message . ' in ' . $file . ' on line ' . $line);
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment