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


1
  • Hope it finds you well. I have the same problem and exact error. A temporary solution? What is required afterwards. Is this not going to cause other issues where type is not defined in this way? Or is this just a problem with composer versions? Best way to get the correct dependencies/packages to resolve this problem? I'm using composer 2.18 and have tried the above method of over staying in PHP initially but it hasn't worked same error. Thanks Commented Jul 26, 2024 at 9:21

3 Answers 3

5

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
3

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

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 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.