webman在PHP8.1环境下安装TP-ORM启动报错

leader

PHP Fatal error: During inheritance of ArrayAccess: Uncaught ErrorException: Return type of think\Container::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /www/wwwroot/webman/vendor/topthink/think-container/src/Container.php:567

截图

4313 5 2
5个回答

liziyu

7.4妥当

Tinywan

你这是 think-container 这个依赖包不支持 8.1 。TP-ORM 是支持 8.1的

截图

  • leader 2022-04-07

    think-container可以移除吗 会影响TP-ORM吗

  • Tinywan 2022-04-07

    可以移除,TP-ORM不依赖与think-container

  • leader 2022-04-07

    谢谢大佬,刚看了下think-cache依赖think-container

  • Tinywan 2022-04-07

    我这边用的8.1.1是没问题的

  • leader 2022-04-07

    我本地环境8.1.4 测试TP-ORM同样报错

  • Tinywan 2022-04-07

    composer info 看看版本号是多少

  • Tinywan 2022-04-07

    我这边是 topthink/think-orm v2.0.53 think orm

  • leader 2022-04-07

    topthink/think-helper v3.1.6 The ThinkPHP6 Helper Package
    topthink/think-orm v2.0.12 think orm
    webman/think-orm v1.0.1
    workerman/webman-framework v1.3.9 High performance HTTP Service Framework.

  • leader 2022-04-07

    我这边composer update已经是最新的了

liziyu

这就是不喜欢composer的地方,把祖祖孙孙全部拉下来了。没办法!~

  • Tinywan 2022-04-07

    所有的包管理都一样,最起码比node好一点,那个是真心的大

banro512

thinkphp-container 不兼容 php8.1 导致的

在 PHP 8.1 之前,任何扩展ArrayAccess接口的类都不需要添加返回类型
从 PHP 8.1 及更高版本开始,缺少返回类型的声明会导致弃用通知:

解决方法,打开 \vendor\topthink\think-container\src\Container.php,搜索

offsetExists($key)改为 offsetExists($key):bool
offsetSet($key, $value)改为 offsetSet($key, $value):void
offsetGet($key) 改为 offsetGet($key):mixed
offsetUnset($key)改为 offsetUnset($key):void
getIterator()改为 getIterator():IteratorAggregate
count()改为 count():int

Tinywan

兼容8.1 需要版本大于等于 v2.0.46 版本才会兼容,你这个topthink/think-orm v2.0.12 think ormv2.0.12 就是不兼容的。兼容8.1:https://github.com/top-think/think-orm/commit/c422dbaa80671f120c0fef2acfe28ecb7dd1b794

截图

  • banro512 2022-04-08

    他这个不是 orm的问题,是 安装think-cache 时需要使用think-container ,这个 contrainer里的几个写法没有设置返回类型

  • Tinywan 2022-04-08

    所以让他卸载这个依赖包,单独安装就没问题了

年代过于久远,无法发表回答
🔝