php
build_error
ai_generated
true
警告:类名解析歧义,“App\Models\User”同时存在于“/var/www/app/src/Models/User.php”和“/var/www/app/src/Models/Admin/User.php”中
Warning: Ambiguous class resolution, "App\Models\User" was found in both "/var/www/app/src/Models/User.php" and "/var/www/app/src/Models/Admin/User.php"
ID: php/composer-outdated-autoload
88%修复率
85%置信度
1证据数
2023-11-20首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| composer 2.6 | active | — | — | — |
| composer 2.7 | active | — | — | — |
| php 8.1 | active | — | — | — |
| php 8.2 | active | — | — | — |
根因分析
Composer 自动加载器检测到两个文件声明了相同的完全限定类名,原因是命名空间到目录的映射重叠或不同文件中存在重复的类定义。
English
Composer's autoloader detects two files that both declare the same fully-qualified class name due to overlapping namespace-to-directory mappings or duplicate class definitions in different files.
官方文档
https://getcomposer.org/doc/04-schema.md#autoload解决方案
-
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.
-
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`
80% 失败
The cache clear does not fix the underlying duplicate class mapping; it only removes cached metadata.
-
Renaming one of the files without updating the namespace
95% 失败
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.