magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.52k stars 9.31k forks source link

Upgrade from 2.4.3-p1 to 2.4.4 throws terminal error "Fatal error: During inheritance of Countable" #35306

Closed FadedOut closed 2 years ago

FadedOut commented 2 years ago

UPDATE: THANKS to @loic-paquin for helping pinpoint a change in process with upgrading to 2.4.4. Please see comment 7 for solution!

Preconditions (*)

  1. Magento 2.4.3-p1
  2. Production Mode
  3. Apache 2.4 (no NGINX)
  4. mod_mpm_worker
  5. PHP 7.4.23
  6. Elasticsearch 7.12.1
  7. Redis 6.2.6
  8. MariaDB 10.3.34
  9. Composer 2.1.6 (then upgraded to 2.3.5 because of the errors below thinking this would help but it made no difference)
  10. RabbitMQ 3.9.14
  11. PHP-FPM: on
  12. PHP Handler: fcgi
  13. Followed: https://devdocs.magento.com/guides/v2.4/install-gde/prereq/php-settings.html

Steps to reproduce (*)

These are the steps I did (in this exact order) then receive the error shown below (in terminal). M2.4.3-p1 worked fine btw.

  1. I was on PHP 7.4.23 - I changed to PHP 8.1.4
  2. Ran the following:
    • composer require magento/product-community-edition 2.4.4 --no-update
    • composer require magento/composer-root-update-plugin ~2.0 --no-update
    • composer upgrade
  3. It appeared to complete the files to download/update because it displayed the "generating autoload files" and "funding" lines at the end (no errors).
  4. I tried running "rm -rf var/cache/ ; rm -rf var/page_cache/ ; rm -rf generated/code/* ; bin/magento setup:upgrade"

Expected result (*)

  1. Magento 2.4.4 to work as intended.

Actual result (*)

  1. After running "step 4" above, it simply throws the error shown below. No magento command works - the only command that works is "composer upgrade".

Can't run any of the following without error (with or without php before command):

  1. Error Report: ----ERRORS SHOWN IN CONSOLE/TERMINAL (when executing any command with PHP 8.1)-----
    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 /home/*****/public_html/vendor/composer/composer/src/Composer/Repository/ArrayRepository.php on line 277 in /home/*****/public_html/vendor/magento/framework/App/ErrorHandler.php:61
    Stack trace:
    #0 /home/*****/public_html/vendor/composer/composer/src/Composer/Repository/ArrayRepository.php(28): Magento\Framework\App\ErrorHandler->handler(8192, 'Return type of ...', '/home/*****/publi...', 277)
    #)1 /home/*****/public_html/vendor/composer/ClassLoader.php(571): include('/home/*****/publi...')
    #)2 /home/*****/public_html/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile('/home/*****/publi...')
    #)3 /home/*****/public_html/vendor/composer/composer/src/Composer/Repository/PlatformRepository.php(31): Composer\Autoload\ClassLoader->loadClass('Composer\\Reposi...')
    #)4 /home/*****/public_html/vendor/composer/ClassLoader.php(571): include('/home/*****/publi...')
    #)5 /home/*****/public_html/vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile('/home/*****/publi...')
    #)6 /home/*****/public_html/vendor/composer/composer/src/Composer/Package/Loader/ValidatingArrayLoader.php(375): Composer\Autoload\ClassLoader->loadClass('Composer\\Reposi...')
    #)7 /home/*****/public_html/vendor/composer/composer/src/Composer/Package/Loader/RootPackageLoader.php(70): Composer\Package\Loader\ValidatingArrayLoader::hasPackageNamingError('magento/project...')
    #)8 /home/*****/public_html/vendor/composer/composer/src/Composer/Factory.php(368): Composer\Package\Loader\RootPackageLoader->load(Array, 'Composer\\Packag...', '/home/*****/publi...')
    #)9 /home/*****/public_html/vendor/composer/composer/src/Composer/Factory.php(595): Composer\Factory->createComposer(Object(Composer\IO\BufferIO),Array, false)
    #)10 /home/*****/public_html/vendor/magento/framework/Composer/ComposerFactory.php(47): Composer\Factory::create(Object(Composer\IO\BufferIO), '/home/*****/publi...')
    #)11 /home/*****/public_html/vendor/magento/framework/Composer/ComposerInformation.php(368): Magento\Framework\Composer\ComposerFactory->create()
    #)12 /home/*****/public_html/vendor/magento/framework/Composer/ComposerInformation.php(381): Magento\Framework\Composer\ComposerInformation->getComposer()
    #)13 /home/*****/public_html/vendor/magento/framework/Composer/ComposerInformation.php(244): Magento\Framework\Composer\ComposerInformation->getLocker()
    #)14 /home/*****/public_html/vendor/magento/framework/App/ProductMetadata.php(120): Magento\Framework\Composer\ComposerInformation->getSystemPackages()
    #)15 /home/*****/public_html/vendor/magento/framework/App/ProductMetadata.php(80): Magento\Framework\App\ProductMetadata->getSystemPackageVersion()
    #)16 /home/*****/public_html/vendor/magento/framework/Console/Cli.php(98): Magento\Framework\App\ProductMetadata->getVersion()
    #)17 /home/*****/public_html/bin/magento(22): Magento\Framework\Console\Cli->__construct('Magento CLI')
    #)18 {main} in /home/*****/public_html/vendor/composer/composer/src/Composer/Repository/ArrayRepository.php on line 28

-------ERROR SHOWN IN SYSTEM.LOG (when executing: php bin/magento setup:upgrade with PHP 7.4)------- main.CRITICAL: Type Error occurred when creating object: Magento\Framework\Communication\Config\Data, Magento\Framework\Reflection\TypeProcessor::resolveFullyQualifiedClassName(): Argument #2 ($typeName) must be of type string, null given, called in /home/*****/public_html/vendor/magento/framework/Reflection/TypeProcessor.php on line 550


I apologize if I did something wrong. I don't wish to waste anyone's time. I've spent hours trying to figure out why it's doing this before posting this report, to try and make sure it's not on my end. And I tried researching and there isn't much on this. Hopefully the error log points to a bug.

EDIT: Updated my command processes - with same outcome. Just to clarify. EDIT2: Learning more as I keep trying. Something is up with the PHP changes in Magento I think, EDIT3: Solution info added to top of OP


Please provide Severity assessment for the Issue as Reporter. This information will help during Confirmation and Issue triage processes.

m2-assistant[bot] commented 2 years ago

Hi @FadedOut. Thank you for your report. To speed up processing of this issue, make sure that you provided the following information:

Make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

@magento give me 2.4-develop instance - upcoming 2.4.x release

For more details, review the Magento Contributor Assistant documentation.

Add a comment to assign the issue: @magento I am working on this

To learn more about issue processing workflow, refer to the Code Contributions.


:clock10: You can find the schedule on the Magento Community Calendar page.

:telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

:pencil2: Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

loic-paquin commented 2 years ago

Hey, I got the same issue, what saved me was :

composer require magento/composer-root-update-plugin ~2.0 --no-update composer require-commerce magento/product-community-edition 2.4.4 --no-update composer update

https://experienceleague.adobe.com/docs/commerce-operations/upgrade-guide/prepare/prerequisites.html?lang=en https://experienceleague.adobe.com/docs/commerce-operations/upgrade-guide/implementation/perform-upgrade.html

FadedOut commented 2 years ago

Hey, I got the same issue, what saved me was :

composer require magento/composer-root-update-plugin ~2.0 --no-update composer require-commerce magento/product-community-edition 2.4.4 --no-update composer update

https://experienceleague.adobe.com/docs/commerce-operations/upgrade-guide/prepare/prerequisites.html?lang=en https://experienceleague.adobe.com/docs/commerce-operations/upgrade-guide/implementation/perform-upgrade.html

Hello,

Thank you for your help on this. Unfortunately, I tried exactly that before modifying composer.json manually. The funny part is, I actually looked at that exact site the first time I tried to update. I ran across this error:

"Command "require-commerce" is not defined."

So I assumed something was wrong with the command and went for composer.json instead. But seeing how you mentioned to do it that way I tried again just now. It seems it is a typo.

--This goes through but when doing composer update it says invalid pacakge:-- composer require commerce-magento/product-community-edition 2.4.4 --no-update

--THIS is the correct command:-- composer require magento/product-community-edition 2.4.4 --no-update

But in the end, that did what I did by modifying the composer.json manually. I also saw on that site you linked about the composer-root-update-plugin - I did this as well in my initial trials - I should have put that in the OP - dang. Knew I was missing something.

SUMMARY: Still no fix. Still throws that same error even with running these three commands. Thank you for trying though, any help is very much appreciated.

composer require magento/composer-root-update-plugin ~2.0 --no-update composer require magento/product-community-edition 2.4.4 --no-update composer update

loic-paquin commented 2 years ago

"Command "require-commerce" is not defined." My Bad :

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

It will add the command require-commerce.

The problem you may encouter here is that you're already in php 8.1 but magento 2.4.3 expects php7.4. In this case, composer will fail. In order to fix this you can use update-alternatives --config php to select the php version used by linux.

FadedOut commented 2 years ago

Oh not your fault at all, it's actually a typo on that site you linked. And I'm not sure I understand what you mean when you "It will add the command require-commerce".

But with more testing and your ideas, it does appear to be something up with the PHP versions.

So I did originally try doing it with PHP 7.4 first and it failed half way through when doing the "php bin/magento setup:upgrade" with this error:

Type Error occurred when creating object: Magento\Framework\Communication\Config\Data, Argument 2 passed to Magento\Framework\Reflection\TypeProcessor::resolveFullyQualifiedClassName() must be of the type string, null given, called in /home/cmp/public_html/vendor/magento/framework/Reflection/TypeProcessor.php on line 550

Throws that right after the

Schema post-updates:
Module 'Magento_Amqp':

So that's when I assumed it needed to be on PHP8.1. Then when switching to 8.1 I received the other larger error where no command works at all. It says it is compatible with PHP8.1 so I'm not sure what I'm doing wrong :(

This is odd because I have updated from 2.4.1 -> 2.4.2 -> 2.4.3 -> 2.4.3-p1. Had no issues like this. Must be the PHP changes, IDK.

I do appreciate your help though.

loic-paquin commented 2 years ago

There is no typo, The correct syntax is :

composer require-commerce magento/product-community-edition 2.4.4 --no-update

as stipulated : _WARNING The procedure for upgrading Adobe Commerce and Magento Open Source has changed. You must install a new version of the magento/composer-root-update-plugin package (see prerequisites). In addition, the commands for upgrading have changed from composer require magento/ to composer require-commerce magento/._

And I'm not sure I understand what you mean when you "It will add the command require-commerce". It will allow you to use composer require-commerce for the next step.

I got confused too with require-commerce. But once I installed with this method, it was OK. I'm still facing issues with custom modules but it's not Magento's fault.

Also you definitely need to launch bin/magento setup:upgrade with php 8.1

henryyyt commented 2 years ago

For me it was solved after I added types to all interfaces in my custom module.

Example:

public function get($storeCode); -> public function get(string $storeCode);

FadedOut commented 2 years ago

There is no typo, The correct syntax is :

composer require-commerce magento/product-community-edition 2.4.4 --no-update

as stipulated : _WARNING The procedure for upgrading Adobe Commerce and Magento Open Source has changed. You must install a new version of the magento/composer-root-update-plugin package (see prerequisites). In addition, the commands for upgrading have changed from composer require magento/ to composer require-commerce magento/._

And I'm not sure I understand what you mean when you "It will add the command require-commerce". It will allow you to use composer require-commerce for the next step.

I got confused too with require-commerce. But once I installed with this method, it was OK. I'm still facing issues with custom modules but it's not Magento's fault.

Also you definitely need to launch bin/magento setup:upgrade with php 8.1

That is crazy, I understand there was that warning box but really? Just a single small blip on this? I think it should have been on the 2.4.4 release notes as well or something (unless it was there as well and I missed it there too? If so ugh - I read that whole thing too :( ).

But, that indeed DID IT :) THANK YOU!

The step I was missing out on and to help anyone else that comes across this odd issue/change:

1) STAY IN PHP 7.4 2) composer require magento/composer-root-update-plugin ~2.0 --no-update 3) composer update 4) rm -rf var/cache/ ; rm -rf var/page_cache/ ; rm -rf generated/code/ ; bin/magento setup:upgrade 5) composer require-commerce magento/product-community-edition 2.4.4 --no-update 6) composer update 7) CHANGE TO PHP 8.1 8) rm -rf var/cache/ ; rm -rf var/page_cache/ ; rm -rf generated/code/ ; bin/magento setup:upgrade

It still failed throwing the "main.CRITICAL: Type Error occurred when creating object:" half way through the upgrade process, but when you said about the modules not being compatible it made me think maybe it was a module failing. I assumed when I did composer update it would say which were not compatible with the new version. But dur, I didn't change to PHP 8.1 until after running composer update the second time. So I disabled a bunch of the modules I had and it finished 100%. 👍

I much appreciate the help on this. In the end it seems it was me that somewhat messed up. But at least with this ticket/bug report, anyone else coming across this same problem can be helped.

@henryyyt thank you for that info as well. That will help to fix up some modules to get them compatible with PHP 8.1. For now, disabling them was the quickest solution for me.

C4rter commented 2 years ago

I still have that issue with PHP 8.1.3.

No matter what I do, it keeps saying:

PHP 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 /var/www/html/vendor/composer/composer/src/Composer/Repository/ArrayRepository.php on line 277 in /var/www/html/vendor/magento/framework/App/ErrorHandler.php:61

when I try to run any Magento command like bin/magento setup:upgrade after upgrading to 2.4.4 and switching to PHP 8.1.

It seems the composer folder in vendor/composer is old or something? But even when I deleted it and recreated it with composer install, it stays the same.

My count function in vendor/composer/composer/src/Composer/Repository/ArrayRepository.php looks like this:

/**
     * Returns the number of packages in this repository
     *
     * @return int Number of packages
     */
    public function count()
    {
        if (null === $this->packages) {
            $this->initialize();
        }

        return count($this->packages);
    }
FadedOut commented 2 years ago

@C4rter Yup that sounds like exactly what I was going through. For the lack of sounding repetitive, but to cover all bases, did you read all the previous posts?

Specifically, did you follow the steps I found to work for me exactly? Here:

  1. STAY IN PHP 7.4
  2. composer require magento/composer-root-update-plugin ~2.0 --no-update
  3. composer update
  4. rm -rf var/cache/ ; rm -rf var/page_cache/ ; rm -rf generated/code/* ; bin/magento setup:upgrade
  5. composer require-commerce magento/product-community-edition 2.4.4 --no-update
  6. composer update
  7. CHANGE TO PHP 8.1
  8. rm -rf var/cache/ ; rm -rf var/page_cache/ ; rm -rf generated/code/* ; bin/magento setup:upgrade

Staying with PHP 7.4 all the way to the end is very important. Also, making sure to update to the new 'composer-root-update-plugin' properly is important as well (doing composer require then composer update then rm those folders then setup:upgrade). I missed the step of doing the composer update & setup:upgrade my first time around, so the new command of "composer require-commerce" didn't work for me and I went with the old way of "composer require magento/..." which was not correct.

If you follow that precisely it should work as intended. The error you're getting is the exact one I got and this fixed it for me.

C4rter commented 2 years ago

Thank you for the reply.

I did it the same way you did at the beginning, so the wrong way.

So at first I did not do: composer require magento/composer-root-update-plugin ~2.0 --no-update composer require-commerce magento/product-community-edition 2.4.4 --no-update Just plain old composer require.

And everything was fine when still using PHP 7.4. That was no issue.

But now I switched to 8.1 and the issues started.

Then I found your post and I switched back to 7.4 and did that. composer require-commerce also works as it should.

But it didn't change anything in the vendor/composer/composer/src/Composer/Repository/ArrayRepository.php file for me. That's still old and stays old, even when I delete it and it's recreated with composer install.

I'm clueless what actually changes that contents folder and why it's old.

Can you show how your count() function in vendor/composer/composer/src/Composer/Repository/ArrayRepository.php looks like?

FadedOut commented 2 years ago

I'll attach the file - but oddly mine says it was updated yesterday along with every other file in that folder - which is when I think I was in the middle of trying to figure this out. So I'm not sure honestly when/which version this file is. And simply replacing this file with yours or making changes is probably not the best course of action. It should update correctly if the steps are done in the right order.

So, that error I resolved without doing any file modifications. My 2.4.3-p1 was working great when I updated, so no previous bugs/problems/errors. Then I simply did the steps I just posted (thanks to the help from @loic-paquin pointing out my mistake) and my problem was solved.

Just make sure to run composer update after updating the "composer-root-update-plugin". If you still end up with problems, you'll need to post your exact steps 1 by 1 so I can see where you're going wrong. Also follow my "preconditions" listed in OP, to make sure you at least have the same versions of stack as I do. Most of what I have is required by Magento (things like my Elasticsearch is somewhat off but so far seems to be okay).

ArrayRepository.php in zip attached - this file also states it's part of composer. This "updated file" might be from when I updated to 2.3.5, which might look different from yours depending on your composer version. ArrayRepository.zip

C4rter commented 2 years ago

I had another go at it with your list of steps and now, when doing it from scratch, the composer/src/Composer/Repository/ArrayRepository.php is updated and looks correct now.

But sadly, now everything else is way worse than before.

My bin/magento file is gone. My pub folder is basically emptied out. And various other files are missing. Seems to be a common issue when updating Magento as well. Will look into that now.

Who would have thought the update from 2.4.3 to 2.4.4 would be way worse than going from Magento 1 to 2.

Sental commented 2 years ago

usually the missing magento default files are sorted by deleting vendor/magento and doing a composer install.

The install information from @FadedOut and warning about the new prerequisites need to be added to the release notes.

FadedOut commented 2 years ago

Yikes, yeah sorry to say bud you got something else crazy going on there.

These updates can indeed be a pain sometimes (that's why there are teams that get paid thousands to do the updates for store owners - for this exact reason I believe). I've done updates from 2.4.1 through to this one and had many hiccups for each one. But for the most part, they do always end up successful if done right. Sometimes it's things that were added as well like incompatible modules or themes. Might want to make sure all custom stuff is disabled/removed as well before trying. For me, "bin/magento setup:upgrade" was not finishing simply because of incompatible modules with php8. After disabling/removing them I was good.

I think the primary issue with this release is the PHP 8.x change. Previous releases were all on PHP 7.x. When we change PHP versions (or anything major in the stack) it usually throws wrenches into the process. But in the end, this stack change is good, it will finally push the lazy [3rd party] devs to get going updating their outdated extensions.

FadedOut commented 2 years ago

@Sental I agree, I just quickly looked over the release notes again and don't see anything about the "composer-root-update-plugin" needing to be updated - esp first. I can't remember if I did that update prior to doing the magento update on previous versions. I feel like that is new.

As I mentioned in a previous comment, a little "warning" block on a part of magento docs explaining this isn't enough. I feel like many will run into this issue because of that - esp with this change of step being required. More read the release notes I would think.

Sental commented 2 years ago

There was a warning block with the mysql to elasticsearch search system change. Considering the ramifications of this extra step and the custom command necessary to complete and upgrade it should be there too. @engcom-Alfa @engcom-Hotel maybe this is something for you guys and the internal team to consider for both now and when an upgrade path deviates from the standard composer workflow.

C4rter commented 2 years ago

usually the missing magento default files are sorted by deleting vendor/magento and doing a composer install.

Thank you, yeah, that did it. I removed the vendor folder and did another composer update. Now everything looks good.

Yikes, yeah sorry to say bud you got something else crazy going on there.

Haha, yeah, as I said before. The update from M1 to M2 was less of a hassle than this one. It started the last two days with getting Klarna up and running again (and the new extension not even available in the marketplace) and today that stuff. It's enough issues for a minor version update now.

These updates can indeed be a pain sometimes (that's why there are teams that get paid thousands to do the updates for store owners - for this exact reason I believe).

Yeah I was one of these guys till two years ago and since 2010. But I switched jobs and now I only have one Magento store I keep working for on my own time and for my day job I do something different.

I think the primary issue with this release is the PHP 8.x change. Previous releases were all on PHP 7.x. When we change PHP versions (or anything major in the stack) it usually throws wrenches into the process. But in the end, this stack change is good, it will finally push the lazy [3rd party] devs to get going updating their outdated extensions.

I've switched from 7.1 to 7.4 not so long ago and that went pretty good. But yeah, that and I think they might have changed too much in one release. Removal of many payment providers. PHP version change and much more. If think I'm lucky that the store I manage has very little customization done. Part of the reason I keep doing that.

And thanks again for your step by step guide. Doing that, from scratch, sorted out my issues then.

FadedOut commented 2 years ago

Thank you, yeah, that did it. I removed the vendor folder and did another composer update. Now everything looks good.

Oh good, it sounds like his info helped because I had no idea past what I was saying unfortunately. And I didn't even think of removing the vendor/magento files - I suppose that makes sense. Maybe remanence of older modules colliding? I love github :)

Haha, yeah, as I said before. The update from M1 to M2 was less of a hassle than this one. It started the last two days with getting Klarna up and running again (and the new extension not even available in the marketplace) and today that stuff. It's enough issues for a minor version update now.

lol that's crazy that M1 to M2 was easier than this. In that case, they definitely should have documented the processes better (esp being a month past original release date no-less). No way this should have been harder than an entire codebase change (M1 -> M2). This is why Magento updates scare me :(. You never know how it will go, when you think it will be smooth/easy, most likely it won't be. And then the downtime/loss of business = no good. Then they leave for us on github to figure it out lol.

Yeah I was one of these guys till two years ago and since 2010. But I switched jobs and now I only have one Magento store I keep working for on my own time and for my day job I do something different.

The good thing I think I find is that when Magento is running well it seems to stay that way. So at least, being able to run a estore and do something else during the day is somewhat possible.

I've switched from 7.1 to 7.4 not so long ago and that went pretty good. But yeah, that and I think they might have changed too much in one release. Removal of many payment providers. PHP version change and much more. If think I'm lucky that the store I manage has very little customization done. Part of the reason I keep doing that.

Yeah 7.1 -> 7.4 isn't as drastic of a stack change. It's exactly like how the days of 5.6 - 7.x went. Many devs delayed delayed delayed because they knew it would be a pain to move to 7.x. Well, it seems about the same with 8.x., except maybe a bit smoother because 8.0 has only been out since nov 2020, so like 1.5 yrs. That's not bad for major platforms (ie. Magento, Wordpress/WC, I'm sure there's more) to be running on it. I know in the end here, I'm glad for the change, bring us into modern times/tech.

And thanks again for your step by step guide. Doing that, from scratch, sorted out my issues then.

No problem at all. Glad you were able to get it up and running. There is nothng worse than being stuck and not being able to find help. I know that feeling. I got helped then that help was able to help others lol.

TuVanDev commented 2 years ago

@FadedOut @C4rter Magento guide for upgrade magento version already mentioned require installing the Composer update plugin.

https://devdocs.magento.com/guides/v2.4/comp-mgr/cli/cli-upgrade.html

FadedOut commented 2 years ago

@Viper9x Indeed, even on the page it's moving to it shows it. On the page you linked it says to run the update command for the root update plugin then to run the "composer update" command. On the new page it does not say that (to run composer update). I simply made the mistake and forgot to do that (I only looked at the new page it's moving to). I mentioned this in previous comments, that I made that mistake.

We simply thought maybe it could be clarified better and maybe in more than just one place. But you are right, it does say it.

Sental commented 2 years ago

It is a matter of inadequate communication then. Even though it was there, the Magento team and the release notes team specifically need to do better to enable a better developer experience.

snez commented 2 years ago

I couldn't get around this with the recommendations so I added

#[\ReturnTypeWillChange]

before the method declaration at:

Then setup:upgrade completed successfully.

i.e.

    /**
     * Returns the number of packages in this repository
     *
     * @return int Number of packages
     */
    #[\ReturnTypeWillChange]
    public function count()
    {
        if (null === $this->packages) {
            $this->initialize();
        }

        return count($this->packages);
    }
C4rter commented 2 years ago

I couldn't get around this with the recommendations so I added

#[\ReturnTypeWillChange]

before the method declaration at:

* vendor/composer/composer/src/Composer/Repository/CompositeRepository.php::count()
* vendor/composer/composer/src/Composer/Repository/ArrayRepository.php::count()

Then setup:upgrade completed successfully.

But beware, I guess that is a slippery slope as you have an unintended/wrong composer module version in your vendor folder which can change with every new change involving composer update or install.

snez commented 2 years ago

@C4rter there is no way to upgrade it. If I delete the folder and run the composer require commands for root plugin ~2.0 and magento community 2.4.4, it just re-installs the same composer module with the deprecated functionality.

Edit: I'm on PHP 8.1.4 and the latest composer is incompatible with it

C4rter commented 2 years ago

@C4rter there is no way to upgrade it. If I delete the folder and run the composer require commands for root plugin ~2.0 and magento community 2.4.4, it just re-installs the same composer module with the deprecated functionality.

Edit: I'm on PHP 8.1.4 and the latest composer is incompatible with it

A few of us here had the same issue and we all fixed it. I also thought there is no way to upgrade it at one point. But then I started from scratch, meaning PHP 7.4 and Magento 2.4.3 and the matching DB. And then I did the 8 steps from @FadedOut and then it actually did upgrade that module.

Sure, I had another issue then with files missing which lead me to completely remove the vendor folder again and composer install once again. But it still used the newer composer module version that time as well and after that everything was updated and working.

In the end it's your decision, but I wouldn't call it a day with that setup now. That would be too unstable for me. you should never have to rely on manual changes of files in the vendor folder. That never goes well in the end.

FadedOut commented 2 years ago

@C4rter there is no way to upgrade it. If I delete the folder and run the composer require commands for root plugin ~2.0 and magento community 2.4.4, it just re-installs the same composer module with the deprecated functionality.

Edit: I'm on PHP 8.1.4 and the latest composer is incompatible with it

@snez If you reference the OP, you'll see I am on PHP 8.1.4 as well as Composer 2.3.5. I'm currently using Magento 2.4.4 with no issues now (other than the obvious theme/modules issues which is not Magento's fault).

As @C4rter points out, modifying base files (not a 3rd party module or theme) is usually never a good idea and is not intended to be done to work.

If you follow all steps properly, it should upgrade. It is possible. I know it seems like it just won't work, but something is mis-configured on your end to make it that way. In the OP, I gave every single stack info I am using, make sure to have those versions or better at least. M2.4.4 is requiring newer releases of the stack this time around. These make a difference.

snez commented 2 years ago

@FadedOut @C4rter I followed your advise and restarted the process from scratch, and all I managed to do was to bring the error back. Here are the exact commands I used:

$ rm -rf vendor/composer
$ brew unlink php
$ brew link php@7.4
$ php -v
PHP 7.4.28 (cli) (built: Feb 28 2022 07:33:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies
$ 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
$ brew unlink php
$ brew link php@8.1
$ php -v
PHP 8.1.4 (cli) (built: Mar 18 2022 09:32:37) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.4, Copyright (c) Zend Technologies
    with Xdebug v3.1.4, Copyright (c) 2002-2022, by Derick Rethans
    with Zend OPcache v8.1.4, Copyright (c), by Zend Technologies
$ rm -rf var/cache/* ; rm -rf var/page_cache/* ; rm -rf generated/code/* ; bin/magento setup:upgrade
PHP 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 vendor/magento/framework/App/ErrorHandler.php:61
Stack trace:
#0 vendor/composer/composer/src/Composer/Repository/ArrayRepository.php(28): Magento\Framework\App\ErrorHandler->handler(8192, 'Return type of ...', '/Users/snez/Pro...', 277)
...
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 vendor/magento/framework/App/ErrorHandler.php:61
Stack trace:
#0 vendor/composer/composer/src/Composer/Repository/ArrayRepository.php(28): Magento\Framework\App\ErrorHandler->handler(8192, 'Return type of ...', '/Users/snez/Pro...', 277)

And

$ zsh --version
zsh 5.8 (x86_64-apple-darwin21.0)
$ composer -V                                                                                                                                                                                                                  
Composer version 2.3.5 2022-04-13 16:43:00

I am also attaching the generated composer.json file if any dev wants to take a look composer.txt

Nothing indicates that I have an outdated composer module, it seems to be the latest one.

Here is even the latest ArrayRepository.php::count() method on the latest composer branch on Github: https://github.com/composer/composer/blob/main/src/Composer/Repository/ArrayRepository.php#L321-L333

There are some forks of composer which have already performed the #[\ReturnTypeWillChange] fix, but the main branch of composer hasn't

C4rter commented 2 years ago

@snez

That's correct, the main branch of composer is still for Composer 1.

The composer module version that needs to be required and installed is that one: https://github.com/composer/composer/tree/2.2 From the 2.2 branch.

Here's the file in question: https://github.com/composer/composer/blob/2.2/src/Composer/Repository/ArrayRepository.php As you can see, the comments are there.

That's how it should look like in the composer.lock:

{
            "name": "composer/composer",
            "version": "2.2.x-dev",
            "source": {
                "type": "git",
                "url": "https://github.com/2tvenom/CBOREncode.git",
                "reference": "42aedccb861d01fc0554782348cc08f8ebf22332"
            },
            "dist": {
                "type": "zip",
                "url": "https://api.github.com/repos/2tvenom/CBOREncode/zipball/42aedccb861d01fc0554782348cc08f8ebf22332",
                "reference": "42aedccb861d01fc0554782348cc08f8ebf22332",
                "shasum": ""
            },
            "require": {
                "composer/ca-bundle": "^1.0",
                "composer/metadata-minifier": "^1.0",
                "composer/pcre": "^1.0",
                "composer/semver": "^3.0",
                "composer/spdx-licenses": "^1.2",
                "composer/xdebug-handler": "^2.0 || ^3.0",
                "justinrainbow/json-schema": "^5.2.11",
                "php": "^5.3.2 || ^7.0 || ^8.0",
                "psr/log": "^1.0 || ^2.0",
                "react/promise": "^1.2 || ^2.7",
                "seld/jsonlint": "^1.4",
                "seld/phar-utils": "^1.0",
                "symfony/console": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0",
                "symfony/filesystem": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0",
                "symfony/finder": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0",
                "symfony/process": "^2.8.52 || ^3.4.35 || ^4.4 || ^5.0 || ^6.0"
            },
            "require-dev": {
                "phpspec/prophecy": "^1.10",
                "symfony/phpunit-bridge": "^4.2 || ^5.0 || ^6.0"
            },
            "suggest": {
                "ext-openssl": "Enabling the openssl extension allows you to access https URLs for repositories and packages",
                "ext-zip": "Enabling the zip extension allows you to unzip archives",
                "ext-zlib": "Allow gzip compression of HTTP requests"
            },
            "bin": [
                "bin/composer"
            ],
            "type": "library",
            "extra": {
                "branch-alias": {
                    "dev-main": "2.2-dev"
                }
            },
            "autoload": {
                "psr-4": {
                    "Composer\\": "src/Composer"
                }
            },
            "notification-url": "https://packagist.org/downloads/",
            "license": [
                "MIT"
            ],
            "authors": [
                {
                    "name": "Nils Adermann",
                    "email": "naderman@naderman.de",
                    "homepage": "https://www.naderman.de"
                },
                {
                    "name": "Jordi Boggiano",
                    "email": "j.boggiano@seld.be",
                    "homepage": "https://seld.be"
                }
            ],
            "description": "Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.",
            "homepage": "https://getcomposer.org/",
            "keywords": [
                "autoload",
                "dependency",
                "package"
            ],
            "funding": [
                {
                    "url": "https://packagist.com",
                    "type": "custom"
                },
                {
                    "url": "https://github.com/composer",
                    "type": "github"
                },
                {
                    "url": "https://tidelift.com/funding/github/packagist/composer/composer",
                    "type": "tidelift"
                }
            ],
            "time": "2022-04-14T09:25:44+00:00"
        },

Unfortunately I cannot say what is going wrong when you do it.

Whats the "minimum-stability" value set to in you composer.json? Mine is: "dev"

tthierryEra commented 2 years ago

Hello,

If it can help others, I had the same issue and I was not able to fix it by running the solution proposed. On my end I needed to update the composer.json file specifically the require-dev section with what is written here https://github.com/magento/magento2/blob/2.4.4/composer.json

This way the propers composer modules were install and the issue disapeared.

snez commented 2 years ago

Thanks @tthierryEra, updating the require-dev dependencies also updated the vendor/composer module!

cc C4rter

FadedOut commented 2 years ago

That is odd, following the instructions on the upgrade guide should have worked. Something must have been different on your side to cause it not to work by the standard process.

But glad you guys were able to get it updated either way 👍

MartinKuhl commented 2 years ago

the following both require-dev dependencies are necessary: magento/composer-root-update-plugin ~2.0 & pdepend/pdepend ~2.10.0

mtkumar82 commented 2 years ago

In vendor/composer/composer/src/Composer/Repository/ArrayRepository.php

just add #[\ReturnTypeWillChange] before count function like below

[\ReturnTypeWillChange]

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

    return count($this->packages);
}

In line around 277, and this worked for me. Or where ever you found same issue just add #[\ReturnTypeWillChange] before function in custom extensions too. Hope it will help someone else too,

oleksiy-iwdagency commented 2 years ago

Not sure why, but I had version 2.1.0 in composer.lock. I upgraded package "composer/composer" to 2.2+ manually and it fixed the issue for me. composer require composer/composer:~2.2.0

hostep commented 2 years ago

Or just run composer update composer/composer --with-all-dependencies, that's probably better than adding a version constraint on composer/composer to ~2.2.0 in your composer.json file as this will cause problems when trying to upgrade to newer Magento versions in the future most likely.

davirs commented 2 years ago

We also need to update composer root of magento (example public_html/)

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

amcguireweb commented 2 years ago

Or just run composer update composer/composer --with-all-dependencies, that's probably better than adding a version constraint on composer/composer to ~2.2.0 in your composer.json file as this will cause problems when trying to upgrade to newer Magento versions in the future most likely.

I tried to do this, but it didn't change anything. I had to manually modify the version of composer/composer in my composer.json file to allow it to update the version required in composer.lock. I'd really be interested in knowing what may have caused this.

hostep commented 2 years ago

Well, for one thing, you really shouldn't have composer/composer in your Magento's project composer.json file.

Magento did have this a very long time ago, in the 2.0.x, 2.1.x and 2.2.x versions, but it was removed in 2.3.x and 2.4.x versions, so you might have it as a left-over that never got cleaned up? I would strongly suggest you setup a new Magento project from scratch using the exact version that you are using and then take a look at the resulting composer.json file, so you can compare it with your own, maybe you'll find more interesting changes that haven't been reflected in your own file...

codebase-md commented 2 years ago

In our case it was the require-dev section of the root composer.json. It had not been updated to the requirements of 2.4.5 thus working with old versions of phpmd/phpmd which requires composer/xdebug-handler (^1.0). This was blocking the update of composer/composer in our case.

Kerolusnasser commented 2 years ago

i faced this issue while upgrading to 2.4.5-p1 in my case the issue was in require-dev section: "pdepend/pdepend": "~2.7.0" needed to be updated manually to "pdepend/pdepend": "~2.10.0" Now fixed

sdouma commented 1 year ago

Hello,

If it can help others, I had the same issue and I was not able to fix it by running the solution proposed. On my end I needed to update the composer.json file specifically the require-dev section with what is written here https://github.com/magento/magento2/blob/2.4.4/composer.json

This way the propers composer modules were install and the issue disapeared.

my man, your cookie is on its way

bruce-gemberling commented 1 year ago

I can confirm that using this require-dev in my composer.json file in Magento 2.4.5-p1 was exactly what allowed me to complete composer2 update and then successfully complete setup:upgrade:

"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" },

dharake commented 1 year ago

This issue has been kicking my butt for almost a year now. I'm on 2.4.5-p1 and still stuck on php7.4. Got over 30 modules installed, it's a nightmare to solve.

TuVanDev commented 1 year ago

@dharake Could you please add composer.json content and your errors when you try to upgrade here? I'll try to help you to pass your nightmare. I've helped a lot of people with upgrading from an earlier Magento version to 2.4.4... or 2.4.5-p1.

dharake commented 1 year ago

@Viper9x I really appreciate the reach out. I will email you now.

erikffflabel commented 1 year ago

How i fixed the same issue:

  1. composer require magento/composer-root-update-plugin ~2.0 --no-update
  2. composer update
  3. removed composer.lock file
  4. changed require-dev/require module versions to the latest
  5. composer require-commerce magento/product-community-edition 2.4.4 --no-update
  6. composer update
bugToaster commented 1 year ago

I encountered an issue with the fastcgi_backend variable, which may require your attention. It would be helpful if you could review the nginx.conf.sample file. I made modifications to the configuration file in the sites-available directory to accommodate the need for running multiple Magento instances.