thinkphp6目前不支持PHP8.0
2022-07-28 14:14:58
192
{{single.collect_count}}

tp官方于2021年01月11日更新了6.0.6版本,已经支持了php8.0

composer update topthink/framework

PHP 8在PHP类型系统中进行了一些改进,例如,引入了Union Types,mixedtype等。

经过这些更改,Reflection API的某些方法会产生错误的结果。

在PHP8中,废弃了ReflectionParameter类中的三个方法

ReflectionParameter::getClass()

ReflectionParameter::isArray()

ReflectionParameter::isCallable()

thinkphp6框架的容器默认使用了ReflectionParameter::getClass(),在PHP8环境中直接报错中断。

Deprecated: Method ReflectionParameter::getClass() is deprecated in D:\WWW\tp6\vendor\topthink\framework\src\think\Container.php on line 443

ReflectionParameter::getClass()返回参数类的名称。但是,当使用联合类型时,null如果差异类类型在单个联合中,则它将返回。

ReflectionParameter::getType()取代getClass()方法。

请注意,getClass()方法会传回实作的ReflectionClass()物件__toString()。

如果只对名称感兴趣,则可以使用$param->getType()->getName()来返回名称

ReflectionParameter::isArray()在PHP 8中已弃用,因为它仅适用于array和?array类型,而不适用于Union类型。

ReflectionParameter::getType() result可以用来模拟这种方法的结果:

$isArray = $param->getType() && $param->getType()->getName() === 'array';

ReflectionParameter::isCallable()在PHP 8中也已弃用,与相似isArray(),它仅适用于callable和?callable参数,但在Union Type中使用时无效。

ReflectionParameter::getType()result也可以用于模拟此方法的结果isCallable:

$isCallable = $param->getType() && $param->getType()->getName() === 'callable';

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}