0

facing error when i upgrade magento 2.4.4 with php 8.1, mysql 8.0 and using composer upgrade getting error below

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


3 Answers 3

4

I think the problem may be that you've upgraded to PHP 8.1 before you've upgraded your composer packages. Have a read of this github issue, seems others had the same issue:

From this thread, it seems like the accepted approach is:

  • STAY IN PHP 7.4
  • composer require magento/composer-root-update-plugin ~2.0 --no-update
  • composer update
  • rm -rf var/cache/* ; rm -rf var/page_cache/* ; rm -rf generated/code/*; - bin/magento setup:upgrade
  • composer require-commerce magento/product-community-edition 2.4.4 --no-update
  • composer update
  • CHANGE TO PHP 8.1
  • rm -rf var/cache/* ; rm -rf var/page_cache/* ; rm -rf generated/code/*;
  • bin/magento setup:upgrade

Of course, if you're a developer and owner of your codebase - I'd advise you first check for any overwritten files that may need updating as part of the upgrade with https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper

1
  • It works, just a comment: the second 'composer update' needs to run with php8.1. Commented Apr 14, 2023 at 11:44
2

Thanks Liam Toohey, But not worked. I found another solution. That is worked

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);
}
1

Temporary solution:

vendor\composer\composer\src\Composer\Repository\ArrayRepository.php 
or 
vendor/composer/composer/src/Composer/Repository/CompositeRepository.php

// public function count()
   public function count(): int

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.