'disabled', 'line' => 0]; } // 生产环境使用更轻量的方式 if (app()->isDebug()) { // 开发环境:详细信息 return self::getDetailedCallerInfo($depth); } else { // 生产环境:基本信息 return self::getBasicCallerInfo($depth); } } private static function getDetailedCallerInfo(int $depth): array { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth + 2); return $backtrace[$depth] ?? ['file' => 'unknown', 'line' => 0]; } private static function getBasicCallerInfo(int $depth): array { // 使用更轻量的方法 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $depth + 2); $caller = $backtrace[$depth] ?? []; return [ 'file' => $caller['file'] ?? 'unknown', 'line' => $caller['line'] ?? 0, 'function' => $caller['function'] ?? 'unknown' ]; } }