1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Slim 3とSlim 4のContainerInterfaceはnamespaceが違う

Posted at

背景

社内にSlim 3のPJとSlim 4のPJがあって、Slim 4側は最近実装された新規開発でだいぶきれいに書かれていたので、レガシーなプロジェクト(Slim 3)のリファクタリング時にSlim 4の実装を真似していたらハマりました。
(こんな状況はなかなかないので参考にならなそうですが。。。)

TypeError: Argument 1 passed to app\helpers\XxxHelper::__construct() must be an instance of Psr\Container\ContainerInterface, instance of Slim\Container given, called in /xxx/app/app.php on line 75 in xxxxx.php on line 19

結論

Slim\Containerを見てもimplements ContainerInterfaceしてるのになぜ?ってなってしまいましたが、
よくよくその定義を確認すると、Slim 3とSlim 4では ContainerInterface のnamespaceが違いました。
参考: https://stackoverflow.com/a/38270475

Slim 3: Interop\Container\ContainerInterface
Slim 4: Psr\Container\ContainerInterface

コピペしすぎに気をつけます。。。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?