当我升级 Magento 2.4.4 时,我得到了 Deprecated Functionality: Return type of Composer\Repository\CompositeRepository::count()

When I upgrading Magento 2.4.4 I am getting Deprecated Functionality: Return type of Composer\Repository\CompositeRepository::count()

当我将 Magento 2.4.3 升级到 2.4.4 时,出现 php8.1 已弃用的功能错误。

PHP 致命错误:在继承 Countable 期间:未捕获的异常:已弃用的功能:Return 类型的 Composer\Repository\CompositeRepository::count() 应该与 [=19= 兼容](): int,或者应该使用#[\ReturnTypeWillChange]属性暂时抑制/var/www/html/vendor/composer/composer/src/Composer/Repository/CompositeRepository.php第180行/var/www/html/vendor/magento/framework/App/ErrorHandler.[中的通知。 =22=]:61

从 PHP 8.1 开始,您必须修复函数 count() 的 return 类型。我们需要修改2个文件。

将 public 函数 count() 更改为 public 函数 count(): int

转到 => \vendor\composer\composer\src\Composer\Repository\ArrayRepository.php(第 277 行)

public function count(): int
{
    if (null === $this->packages) {
        $this->initialize();
    }

    return count($this->packages);
}

转到 => vendor\composer\composer\src\Composer\Repository\CompositeRepository.php(第 180 行)

public function count(): int
{
    $total = 0;
    foreach ($this->repositories as $repository) {
        /* @var $repository RepositoryInterface */
        $total += $repository->count();
    }

    return $total;
}