6

When I try to execute bin/Magento setup:install from command line I get an exception as "Deprecated Functionality: Function ReflectionType::__toString() is deprecated". It gives the same error for my previous Magento instance when I do

bin/magento setup:upgrade

It was running all good a few days earlier.

Any solution for this?

Note: I am using PHP 7.4 on my machine and installed Magento 2.3

Thank You

2

3 Answers 3

24

Magento 2.3 is not compatible with Php 7.4, So there are two possible solutions:

  1. Downgrade you Php version to 7.3 - Recommended
  2. If it is not possible for you to downgrade php version, you need to perform few changes in core files. This is a work around until Magento get compatible version for Php 7.4. When installing on my end I had faced few issues, this is what I did.

Change 1:

File: vendor/zendframework/zend-code/src/Reflection/ParameterReflection.php

In function detectType() replace line return (string) $type; with return $type->getName();

Change 2:

Error: Deprecated Functionality: implode(): Passing glue string after array is deprecated

File: vendor/magento/framework/DB/Sql/UnionExpression.php

In function __toString() replace line $sql = implode($parts, $this->type); with $sql = implode($this->type,$parts);

Change 3:

File: vendor/magento/framework/App/AreaList.php

In function getCodeByFrontName() replace line if ($areaInfo['frontName'] == $frontName) with if (isset($areaInfo) && $areaInfo['frontName'] == $frontName)

Hope you will find it helpfull.

Thanks

4
  • Hello @Abdul Pathan Thanks For this:) Commented Jun 27, 2020 at 19:38
  • Thanks thats work for me (y) Commented Jul 30, 2020 at 13:56
  • Thanks a lot for this answer, it resolved all errors we got after upgrade to php 7.4 in magento 2.3.5 however we are now getting 404 on all product detail pages, do you know any workaround for that? Commented Feb 3, 2021 at 10:25
  • I still get the error even after downgrading to php 7.33.3
    – Black
    Commented Oct 27, 2022 at 9:21
6

One more change in message queue batch consumer file if needed

Deprecated Functionality: Unparenthesized a ? b : c ?: d is deprecated. Use either (a ? b : c) ?: d or a ? b : (c ?: d) in /
vendor/magento/framework-message-queue/BatchConsumer.php on line 154

Before:

$count = $maxNumberOfMessages
            ? $maxNumberOfMessages
            : $this->configuration->getMaxMessages() ?: 1;
        

After:

$count = ($maxNumberOfMessages
            ? $maxNumberOfMessages
            : $this->configuration->getMaxMessages()) ?: 1;

Ref. https://github.com/magento/magento2/blob/2.4/lib/internal/Magento/Framework/MessageQueue/BatchConsumer.php#L154

1

I had Got same ""Deprecated Functionality: Function ReflectionType::__toString() is deprecated" when i was installing magento2.3.6 on php7.4.

I had did some more changes in magento vendor module as above @abdul defined for work in staging server.

File 1: vendor/laminas/laminas-code/src/Reflection/ParameterReflection.php file

Change detectType function if condition where return type is converted in string. I had remove string

if (method_exists($this, 'getType')
        && ($type = $this->getType())
        && $type->isBuiltin()
    ) {
        return $type->getName();
    }

File 2: vendor/magento/module-catalog/Model/Category/Attribute/Backend/Sortby.php

i was changed beforeSave function. updated ternary operator there.

find in beforeSave function.

$attributeValue = is_array($data) ? reset($data) :
                (!empty($data)) ? $data : null;

To

$attributeValue = (is_array($data) ? reset($data) :
                (!empty($data))) ? $data : null;

File 3: vendor/magento/framework/App/AreaList.php

change in public function getCodeByFrontName($frontName) function

find

if ($areaInfo['frontName'] === $frontName) {

And Replace it with

if (isset($areaInfo) && $areaInfo['frontName'] == $frontName) {

As above @abdul describe.

After i had execute successfully "setup:upgrade" and "Static-content:deploy -f" command.

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.