think\Container::get($abstract) must be compatible with Psr\Container\ContainerInterface
我自然是去看一下代码是怎么回事
think\Container这个类实现了Psr\Container\ContainerInterface这个接口
Psr\Container\ContainerInterface这个接口里面就两个方法
public function get(string $id);
public function has(string $id);
think\Container实现这两个方法是这样写的
public function get($abstract)
{
if ($this->has($abstract)) {
return $this->make($abstract);
}
throw new ClassNotFoundException('class not exists: ' . $abstract, $abstract);
}
public function has($name): bool
{
return $this->bound($name);
}
Psr\Container\ContainerInterface这个接口里面方法的参数是声明了string类型的,而在think\Container这个类里面实现方法参数没有带类型,我把这两个方法的参数添加上string的类型,就不报错了。
虽然问题是解决了,但是想到当初直接使用tp6内置的服务器就没有报错,可能是因为我使用命令行启动tp6自带服务器是使用的php是mac自带的php,而我nginx监听的php-fpm进程是用homebrew安装的,可能是两个php环境配置不一样造成的。我就想问一问,是什么配置导致了php对实现接口的要求变得严格?
最佳答案
