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
CodePudding user response:
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;
}