Magento 2 – Fixing Deprecated Functionality: Function ReflectionType::__toString()

magento2

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

Best Answer

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

Related Topic