0

updating to php7 an older directory script needs to be modified, because of getting ""the each() function is deprecated"". In the following code I tried to replace each into foreach, but I didn't succeed:

    case 'php':
        list (,$php_block) = each($this->_php_blocks);
        $this->_linenum += substr_count($php_block, "\n");
        $php_extract = '';
        if($this->php_extract_vars)
        {
            if (strnatcmp(PHP_VERSION, '4.3.0') >= 0)
            {
                $php_extract = '<?php extract($this->_vars, EXTR_REFS); ?>' . "\n";
            }
            else
            {
                $php_extract = '<?php extract($this->_vars); ?>' . "\n";
            }
        }
        return $php_extract . '<?php '.$php_block.' ?>';
        break;

In the second line I tried

list (,$php_block) = foreach($this as '_php_blocks');

would be great to get some hint thx ARS

ARS
  • 1
  • 1
  • use foreach.... – Zeljka Dec 13 '19 at 12:42
  • *"I tried to replace each into foreach"* I don't see any `foreach` – Cid Dec 13 '19 at 12:42
  • in the second line i put:list (,$php_block) = foreach($this as '_php_blocks'); but the foreach was unexpected – ARS Dec 13 '19 at 12:55
  • Check [the manual](https://www.php.net/manual/en/control-structures.foreach.php). – Jeto Dec 13 '19 at 12:57
  • But it seems like you only want the first item so `$php_block = reset($this->_php_blocks);` should do it. See https://stackoverflow.com/questions/1921421/get-the-first-element-of-an-array – Jeto Dec 13 '19 at 13:00
  • Thank you so much, Jeto - this is exactly what solved the problem – ARS Dec 13 '19 at 13:06

0 Answers0