From 233240fc26b6236c0f2a389123c45224f58b9580 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 27 Jul 2022 17:10:47 +0100 Subject: [PATCH] Log a bit more deprecation info --- CRM/Core/Error.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/CRM/Core/Error.php b/CRM/Core/Error.php index 1a5ffa1c87..1eb7350ad1 100644 --- a/CRM/Core/Error.php +++ b/CRM/Core/Error.php @@ -1068,22 +1068,30 @@ class CRM_Core_Error extends PEAR_ErrorStack { } /** - * Output a deprecated function warning to log file. Deprecated class:function is automatically generated from calling function. + * Output a deprecated function warning to log file. + * + * Deprecated class:function is automatically generated from calling function. * * @param string $newMethod * description of new method (eg. "buildOptions() method in the appropriate BAO object"). - * @param string $oldMethod + * @param string|null $oldMethod * optional description of old method (if not the calling method). eg. CRM_MyClass::myOldMethodToGetTheOptions() */ - public static function deprecatedFunctionWarning($newMethod, $oldMethod = NULL) { + public static function deprecatedFunctionWarning(string $newMethod, ?string $oldMethod = NULL): void { + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 4); if (!$oldMethod) { - $dbt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); - $callerFunction = $dbt[1]['function'] ?? NULL; - $callerClass = $dbt[1]['class'] ?? NULL; + $callerFunction = $backtrace[1]['function'] ?? NULL; + $callerClass = $backtrace[1]['class'] ?? NULL; $oldMethod = "{$callerClass}::{$callerFunction}"; } $message = "Deprecated function $oldMethod, use $newMethod."; - Civi::log()->warning($message, ['civi.tag' => 'deprecated']); + // Add a mini backtrace. Just the function is too little to be meaningful but people are + // saying they can't track down where the deprecated calls are coming from. + $miniBacktrace = []; + foreach ($backtrace as $backtraceLine) { + $miniBacktrace[] = ($backtraceLine['function'] ?? NULL) . '::' . ($backtraceLine['class']); + } + Civi::log()->warning($message . ' ' . implode("\n", $miniBacktrace), ['civi.tag' => 'deprecated']); trigger_error($message, E_USER_DEPRECATED); } -- 2.25.1