Cannot use string offset as an array in php

前端 未结 10 864
南方客
南方客 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 06:56

    Since the release PHP 7.1+, is not more possible to assign a value for an array as follow:

    $foo = ""; 
    $foo['key'] = $foo2; 
    

    because as of PHP 7.1.0, applying the empty index operator on a string throws a fatal error. Formerly, the string was silently converted to an array.

提交回复
热议问题