diff --git a/src/Core/Logger/Handler/ErrorHandler.php b/src/Core/Logger/Handler/ErrorHandler.php index 90c08eacd6..2d311b5150 100644 --- a/src/Core/Logger/Handler/ErrorHandler.php +++ b/src/Core/Logger/Handler/ErrorHandler.php @@ -197,7 +197,7 @@ class ErrorHandler E_STRICT => LogLevel::NOTICE, E_RECOVERABLE_ERROR => LogLevel::ERROR, E_DEPRECATED => LogLevel::NOTICE, - E_USER_DEPRECATED => LogLevel::NOTICE, + E_USER_DEPRECATED => LogLevel::WARNING, ]; } @@ -248,17 +248,29 @@ class ErrorHandler */ public function handleError(int $code, string $message, string $file = '', int $line = 0, ?array $context = []): bool { - if ($this->handleOnlyReportedErrors && !(error_reporting() & $code)) { + if ($this->handleOnlyReportedErrors && !(error_reporting() & $code) && $code !== E_USER_DEPRECATED) { return true; } + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + + array_shift($trace); // Exclude handleError from trace + + if ($code === E_USER_DEPRECATED && $trace[0]['function'] ?? '' === 'trigger_error') { + $calledPlace = $trace[1] ?? []; + + $message .= sprintf( + ' It was called in `%s`%s.', + $calledPlace['file'], + isset($calledPlace['line']) ? ' in line ' . $calledPlace['line'] : '' + ); + } + // fatal error codes are ignored if a fatal error handler is present as well to avoid duplicate log entries if (!$this->hasFatalErrorHandler || !in_array($code, self::$fatalErrors, true)) { $level = $this->errorLevelMap[$code] ?? LogLevel::CRITICAL; $this->logger->log($level, self::codeToString($code).': '.$message, ['code' => $code, 'message' => $message, 'file' => $file, 'line' => $line]); } else { - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); - array_shift($trace); // Exclude handleError from trace $this->lastFatalTrace = $trace; }