Cannot use string offset as an array in php

前端 未结 10 867
南方客
南方客 2020-11-29 06:35

I\'m trying to simulate this error with a sample php code but haven\'t been successful. Any help would be great.

\"Cannot use string offset as an array\"

10条回答
  •  旧时难觅i
    2020-11-29 07:11

    I was able to reproduce this once I upgraded to PHP 7. It breaks when you try to force array elements into a string.

    $params = '';
    foreach ($foo) {
      $index = 0;
      $params[$index]['keyName'] = $name . '.' . $fileExt;
    }
    

    After changing:

    $params = '';
    

    to:

    $params = array();
    

    I stopped getting the error. I found the solution in this bug report thread. I hope this helps.

提交回复
热议问题