# 警告：类名解析歧义，“App\Models\User”同时存在于“/var/www/app/src/Models/User.php”和“/var/www/app/src/Models/Admin/User.php”中

- **ID:** `php/composer-outdated-autoload`
- **领域:** php
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

Composer 自动加载器检测到两个文件声明了相同的完全限定类名，原因是命名空间到目录的映射重叠或不同文件中存在重复的类定义。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| composer 2.6 | active | — | — |
| composer 2.7 | active | — | — |
| php 8.1 | active | — | — |
| php 8.2 | active | — | — |

## 解决方案

1. ```
   Run `composer dump-autoload -o` to regenerate the optimized autoload map, then check the generated `vendor/composer/autoload_classmap.php` for duplicate entries and remove the incorrect one.
   ```
2. ```
   Refactor the namespace: move `App\Models\Admin\User` to a distinct namespace like `App\Models\AdminUser` or adjust the PSR-4 prefix in `composer.json` to avoid overlap.
   ```

## 无效尝试

- **Clearing the Composer cache with `composer clear-cache`** — The cache clear does not fix the underlying duplicate class mapping; it only removes cached metadata. (80% 失败率)
- **Renaming one of the files without updating the namespace** — The class name is defined by the namespace and class declaration in the file, not the filename; renaming the file without changing the class declaration does not resolve the ambiguity. (95% 失败率)
