/** * Converts generic PHP errors to \ErrorException * instances, before passing them off to be handled. * * This method MUST be compatible with set_error_handler. * * @param int $level * @param string $message * @param string $file * @param int $line * * @return bool * @throws ErrorException */ public function handleError($level, $message, $file = null, $line = null) { if (!$this->registeredPatterns) { // Just forward to parent function is there aren't no registered patterns. return parent::handleError($level, $message, $file, $line); } // If there are registered patterns, only handle errors if error matches one of the patterns. if ($level & error_reporting()) { foreach ($this->registeredPatterns as $entry) { $pathMatches = (bool) preg_match($entry["pattern"], $file); if ($pathMatches) { return parent::handleError($level, $message, $file, $line); } } } // Propagate error to the next handler, allows error_get_last() to work on silenced errors. return false; }