8

I have been getting this error since I changed to PHP-7.2

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /var/www/html/vedic/vendor/colinmollenhour/cache-backend-file/File.php on line 81

The function is on line 81.

//Don't use parent constructor
while (list($name, $value) = each($options)) {
    $this->setOption($name, $value);
}
0

5 Answers 5

13

each() function is deprecated in php 7.2 so change this function to foreach()

Change

while (list($name, $value) = each($options)) {
    $this->setOption($name, $value);
}

To

foreach ($options as $name => $value) {
    $this->setOption($name, $value);
}
2
  • 1
    You can't just change core files. Also this is probably not the only issue with 7.2
    – 7ochem
    Commented Jul 15, 2018 at 9:35
  • Magento 2.3 now supports PHP 7.2, but this answer helped me fix an issue with a 3rd party extension, thanks !
    – David
    Commented Dec 8, 2018 at 14:59
8

Magento 2 does not support PHP 7.2 until version 2.3 which is not out yet (rumour is it'll be out by the end of 2018).

So your only real option here is to downgrade to the latest supported version of PHP (check the DevDocs for your version of Magento: https://devdocs.magento.com/guides/v2.2/install-gde/prereq/prereq-overview.html#php).

You could also ignore this error and run the risk of hitting other compatibility issues but that wouldn't be advisable. There will likely be many more errors across your site.

4

As mentioned above Magento before 2.3 (unreleased yet) doesn't support PHP 7.2.

There is a separate repo tracking support for PHP 7.2 https://github.com/magento-engcom/php-7.2-support it's maintained by Magento 2 core team. I'm not sure yet if it was merged to https://github.com/magento/magento2/tree/2.3-develop branch.

4

Instead of the below line you can add new line

Old Line

while (list($name, $value) = each($options)) {

Paste the below new line

foreach ($options as $name => $value) {

1

just please change your PHP version to 7.0 it will start working fine.. don't forget PHP (CLI) also must be 7.0

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.