1

After migrating from php5.6 to php7 The following warning appears.

Line 745: [Warning] Nested by-reference foreach loop, make sure that array modifications (if any) do what you expect foreach ($value['subscribes'] as &$v) { } Line 746: [Warning] Nested by-reference foreach loop, make sure that array modifications (if any) do what you expect foreach ($v as &$val) { }

        foreach ($this->view->service as &$value){
        foreach ($value["subscribes"] as &$v){
            foreach ($v as &$val){
                if(isset($val["info"]["subscribe"]['tariff_label']) && $val["info"]["subscribe"]['tariff_label'] != '') {
                    $val["info"]["subscribe"]['tariff_name'] = $val["info"]["subscribe"]['tariff_label'] .' / '.$val["info"]["subscribe"]['tariff_id'];
                }
            }

            unset($val);
        }
        unset($v);
    }
    unset($value);

I couldn't find how to fix this. I don't even understand what the problem is. If anyone knows, please help.

Dragon
  • 11
  • 1
  • 1
    A warning isn't _necessarily_ a problem - it doesn't cause a crash. It's just that - a warning. It's asking you to be careful because when you pass values by reference into a loop, if you then modify those items (as you're doing), the results may or may not be quite what you expected. If you've tested it thoroughly and are confident the code is working as you wish, then you can probably just ignore it. – ADyson Sep 09 '20 at 08:08
  • if you want to learn more details check this: https://stackoverflow.com/questions/10057671/how-does-php-foreach-actually-work/14854568#14854568 – Hirumina Sep 09 '20 at 08:11

0 Answers0