__call似乎不能在laravel控制台命令中工作


__call doesn't seem to work inside laravel console command

我不知道为什么__call在这种情况下不起作用。这是否与Command的实现方式有关,还是我做错了什么?

class MyCommand extends Command
{
    protected $reports = [];
    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'test';
    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '';
    public function __call($methodName, $args) {
        return call_user_func_array($methodName, $args);
    }
}

如果要扩展Command基类,可以重写execute方法。这实际上就是

    /**
     * Execute the console command.
     *
     * @param  'Symfony'Component'Console'Input'InputInterface  $input
     * @param  'Symfony'Component'Console'Output'OutputInterface  $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // your custom logic here to be ran before all handlers, e.g.
        // setting up env variables, prompting user, ...
        
        $method = method_exists($this, 'handle') ? 'handle' : '__invoke';
        return (int) $this->laravel->call([$this, $method]);
    }