【问题标题】:TypeError on any artisan commands任何工匠命令上的 TypeError
【发布时间】:2020-11-29 19:05:18
【问题描述】:
  • Laravel 版本:7.23.0
  • PHP 版本:7.4.8
  • 数据库驱动和版本:MySQL v8.0.21

由于当前的漏洞(https://blog.laravel.com/laravel-cookie-security-releases),今天早上我将 Laravel 升级到了 7.23.0 版本。但现在每个 Artisan Command 都会收到以下错误消息:

php artisan package:discover --ansi

   TypeError 

  Illuminate\Container\Container::bind(): Argument #2 ($concrete) must be of type Closure|string|null

  at vendor/laravel/framework/src/Illuminate/Container/Container.php:238
    234|         // bound into this container to the abstract type and we will just wrap it
    235|         // up inside its own Closure to give us more convenience when extending.
    236|         if (! $concrete instanceof Closure) {
    237|             if (! is_string($concrete)) {
  > 238|                 throw new \TypeError(self::class.'::bind(): Argument #2 ($concrete) must be of type Closure|string|null');
    239|             }
    240| 
    241|             $concrete = $this->getClosure($abstract, $concrete);
    242|         }

      +11 vendor frames 
  12  [internal]:0
      Illuminate\Foundation\Application::Illuminate\Foundation\{closure}(Object(Facade\Ignition\IgnitionServiceProvider))

      +5 vendor frames 
  18  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

由于我认为这将是一个更明显的错误,并且我在 GitHub 上没有发现问题,所以我没有打开新问题并在这里寻求帮助 :)

但是,我真的不知道究竟是什么导致了这个问题。

【问题讨论】:

  • 你可以检查这个github.com/laravel/framework/pull/33539 我认为你还需要显示完整的堆栈跟踪,你还需要确保你的外观/点火版本
  • 尝试删除bootstrap/cache/文件并更新作曲家

标签: php laravel


【解决方案1】:

感谢 Abdel-aziz hassan 提供链接 (https://github.com/laravel/framework/pull/33539)。

我发现门面/点火装置在旧版本上。我更新了它,现在它可以工作了。

谢谢大家!

【讨论】:

    【解决方案2】:

    在我的情况下,使用 instance 而不是 bind 对我有帮助。

    $app->instance(Service::class, $serviceInstance)
    

    改为

    $app->bind(Service::class, $serviceInstance)
    

    【讨论】:

      猜你喜欢
      • 2020-02-05
      • 2014-08-30
      • 1970-01-01
      • 2019-03-13
      • 2014-09-07
      • 2020-12-25
      • 2016-05-05
      • 2017-10-03
      • 2023-04-05
      相关资源
      最近更新 更多