previousErrorHandler = set_error_handler([$this, 'handleError']); } /** * Disable error handler */ public function deactivate() { restore_error_handler(); $this->previousErrorHandler = null; } /** * Error Handler to mute expected messages * * @link https://php.net/set_error_handler * * @param integer $errno Error level * @param $errstr * @param $errfile * @param $errline * @param $errcontext * * @return bool */ public function handleError($errno, $errstr, $errfile, $errline, $errcontext = []) { if ($this->allowUndefinedVars && $errstr == 'Attempt to read property "value" on null') { return; // suppresses this error } if ($this->allowUndefinedArrayKeys && preg_match( '/^(Undefined array key|Trying to access array offset on value of type null)/', $errstr )) { return; // suppresses this error } // pass all other errors through to the previous error handler or to the default PHP error handler return $this->previousErrorHandler ? call_user_func($this->previousErrorHandler, $errno, $errstr, $errfile, $errline, $errcontext) : false; } }