无法声明类' TestCommandRun',因为该名称已被使用

时间:2017-12-09 19:46:00

标签: php laravel laravel-5

我正在使用laravel 5.4

我正在使用php artisan list,但收到以下错误:

C:\Users\admin\Desktop\Coding Projects\demo_laravel>php artisan list
PHP Fatal error:  Cannot declare class TestCommandRun, because the name is already in use in C:\Users\admin\Desktop\Coding Projects\demo_laravel\app\Console\Commands\TestCommandRun.php on line 109
PHP Stack trace:
PHP   1. {main}() C:\Users\admin\Desktop\Coding Projects\demo_laravel\artisan:0
PHP   2. App\Console\Kernel->handle() C:\Users\admin\Desktop\Coding Projects\demo_laravel\artisan:37
PHP   3. App\Console\Kernel->getArtisan() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:121
PHP   4. Illuminate\Console\Application->resolveCommands() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php:317
PHP   5. Illuminate\Console\Application->resolve() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\laravel\framework\src\Illuminate\Console\Application.php:242
PHP   6. Illuminate\Foundation\Application->make() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\laravel\framework\src\Illuminate\Console\Application.php:228
PHP   7. Illuminate\Foundation\Application->make() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\laravel\framework\src\Illuminate\Foundation\Application.php:732
PHP   8. Illuminate\Foundation\Application->resolve() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:586
PHP   9. Illuminate\Foundation\Application->build() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:631
PHP  10. ReflectionClass->__construct() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:752
PHP  11. spl_autoload_call() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:752
PHP  12. Composer\Autoload\ClassLoader->loadClass() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:752
PHP  13. Composer\Autoload\includeFile() C:\Users\admin\Desktop\Coding Projects\demo_laravel\vendor\composer\ClassLoader.php:322

In TestCommandRun.php line 109:

  Cannot declare class TestCommandRun, because the name is already in use

我的命令名称正确:

class TestCommandRun extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'TestCommandRun:run';

在我的Kernel.php中,我已将其添加到$commands部分:

protected $commands = [
    '\App\Console\Commands\TestCommandRun',        
];

为什么我收到上述错误消息的任何建议?

1 个答案:

答案 0 :(得分:2)

看起来你有两个具有相同类名using System; using System.Collections.Generic; namespace KvpSequence { class Program { const int numberOfSequences = 4; // each sequence is a set of 4 ints between 1 and 5 static void Main(string[] args) { List<KeyValuePair<int, int>> sequence = new List<KeyValuePair<int, int>>(numberOfSequences * 4); Random rand = new Random(); for (int i = 0; i < numberOfSequences; ++i) { var indexToSet = rand.Next(0, 4); for (int j = 0; j < 4; ++j) sequence.Add(new KeyValuePair<int, int>(rand.Next(1, 6), j == indexToSet ? 1 : 0)); } foreach (var kvp in sequence) Console.WriteLine(kvp); } } } 的命令。所以,你需要删除一个。

此后运行TestCommandRun命令也是个好主意。