简体   繁体   中英

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

When I upgraded Magento 2.4.3 to 2.4.4, I got a php8.1 deprecated functionality error.

PHP Fatal error: During inheritance of Countable: Uncaught Exception: Deprecated Functionality: Return type of Composer\Repository\CompositeRepository::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/html/vendor/composer/composer/src/Composer/Repository/CompositeRepository.php on line 180 in /var/www/html/vendor/magento/framework/App/ErrorHandler.php:61

As of PHP 8.1, you have to fix the return type of the functions count(). We need to modify 2 files.

Change public function count() to public function count(): int

Goto => \vendor\composer\composer\src\Composer\Repository\ArrayRepository.php (line 277)

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

    return count($this->packages);
}

Goto => vendor\composer\composer\src\Composer\Repository\CompositeRepository.php (line 180)

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

    return $total;
}

The most likely issue is that you haven't updated all your dev-requires to the lastest from 2.4.4. It turns out these lock the composer/composer module to 2.0.x if they aren't updated.

只需将作曲家更新到版本 2.3.9 - 在此版本中计数方法包含类型

just update the composer.json with this packages in require

"require": {
    "magento/composer-dependency-version-audit-plugin": "~0.1",
    "magento/composer-root-update-plugin": "^2.0",  
},

Also, Use latest composer mine was ( 2.3.10)

I solved in this way (by composer 2.3.5):

composer2 require magento/composer-root-update-plugin ~2.0 --no-update

composer2 update

Updating dependencies
Lock file operations: 0 installs, 2 updates, 0 removals
  - Upgrading composer/composer (2.1.0 => 2.2.18)
  - Upgrading magento/composer-root-update-plugin (1.1.2 => 2.0.2)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 2 updates, 0 removals
  - Downloading composer/composer (2.2.18)
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
  - Upgrading composer/composer (2.1.0 => 2.2.18): Extracting archive
  - Upgrading magento/composer-root-update-plugin (1.1.2 => 2.0.2): Extracting archive

Using the "require-dev" libs taken from Magento 2.4.4 composer.json https://github.com/magento/magento2/blob/2.4.4/composer.json

"require-dev": { "allure-framework/allure-phpunit": "~1.5.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "friendsofphp/php-cs-fixer": "~3.3.0", "lusitanian/oauth": "~0.8.10", "magento/magento-coding-standard": "*", "magento/magento2-functional-testing-framework": "^3.7", "pdepend/pdepend": "~2.10.0", "phpmd/phpmd": "^2.9.1", "phpstan/phpstan": "~1.2.0", "phpunit/phpunit": "~9.5.0", "sebastian/phpcpd": "^6.0.3", "squizlabs/php_codesniffer": "~3.6.0", "symfony/finder": "^5.2" }

No worries. I was facing silimar issue and fixed by updating the composer package.

composer require composer/composer:~2.2.0 -W

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM