PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 22, 2022

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

 August 22, 2022     magento, magento2     No comments   

Issue

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


Solution

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


Answered By - stalinrajindian
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing