[top-think/think]命令行生成缓存文件异常报错

2023-12-15 900 views
4
执行环境

php-version: 7.1.16 tp-version: 5.1.14

Step1 执行
php think optimize:config

结果: Succeed!

Step2 执行
php think optimize:autoload

Fatal error: Cannot use think\Container as Container because the name is already in use in C:\Program Files (x86)\Jenkins\workspace\dev\runtime\init.php on line 39 Call Stack: 0.2010 353720 1. {main}() C:\Program Files (x86)\Jenkins\workspace\dev\think:0 0.2080 679048 2. think\App->initialize() C:\Program Files (x86)\Jenkins\workspace\dev\think:19 0.2110 746392 3. think\App->init(???) C:\Program Files (x86)\Jenkins\workspace\dev\thinkphp\library\think\App.php:234 [think\exception\ErrorException] Cannot use think\Container as Container because the name is already in use Exception trace: () at C:\Program Files (x86)\Jenkins\workspace\dev\runtime\init.php:39 think\Error::appShutdown() at n/a:n/a

之后直接执行 php think 也是报上面的异常

回答

1

你自己的自定义命令行有类用Container这个名称吗? 看报错是名称重复使用 建议仔细检查下

9

在 common.php 下使用了

use think\Container;

Container::getInstance()->bindTo('http', '\GuzzleHttp\Client');
Container::getInstance()->bindTo('redis', '\Predis\Client');
7

@saybabi 不需要这样设置,直接配置provider.php 文件 返回数组即可