# 警告：date()：依赖系统时区设置不安全。您必须使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法但仍然收到此警告，很可能是时区标识符拼写错误。我们暂时选择了时区 'UTC'，但请设置 date.timezone 来选择您的时区。位于 /var/www/app/src/Utils/DateHelper.php 第 10 行

- **ID:** `php/date-timezone-ini-error`
- **领域:** php
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 95%

## 根因

PHP 时区未在 php.ini（date.timezone）中配置，也未通过 date_default_timezone_set() 设置，导致 PHP 回退到系统猜测，这可能不可靠。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| PHP 5.6 | active | — | — |
| PHP 7.0 | active | — | — |
| PHP 7.4 | active | — | — |
| PHP 8.0 | active | — | — |
| PHP 8.1 | active | — | — |
| PHP 8.2 | active | — | — |
| PHP 8.3 | active | — | — |

## 解决方案

1. ```
   在 php.ini 中设置时区：`date.timezone = 'Asia/Shanghai'`（替换为您的时区）。重启 Web 服务器或 PHP-FPM。
   ```
2. ```
   在 PHP 脚本顶部或引导文件（如 index.php 或 config.php）中添加 `date_default_timezone_set('Asia/Shanghai');`。
   ```
3. ```
   对于 CLI 脚本，在运行脚本之前通过环境变量设置时区：`export TZ='Asia/Shanghai'`。
   ```

## 无效尝试

- **** — The .user.ini file is ignored in module mode; the setting must be in the main php.ini. (70% 失败率)
- **** — PHP validates the timezone string; a typo results in fallback behavior. (80% 失败率)
- **** — The setting may not propagate to all PHP contexts (e.g., CLI or subrequests). (65% 失败率)
