Php7.1 Fatal error: [] operator not supported for

2019-02-27 17:15发布

问题:

This question already has an answer here:

  • Fatal error: [] operator not supported for string error on PHP Array in for loop 2 answers

I built a some function theme option wordpress.

But I am receiving the following error now, what am I doing wrong?

  if(isset($thm_options['custom_font1_eot']))
    $w_custom_font1_src[] = "url('{$thm_options['custom_font1_eot']['url']}?#iefix') format('embedded-opentype')";

  if(isset($thm_options['custom_font1_woff']))   
    $w_custom_font1_src[] = "url('{$thm_options['custom_font1_woff']['url']}') format('woff')";

  if(isset($thm_options['custom_font1_ttf']))
    $w_custom_font1_src[] = "url('{$thm_options['custom_font1_ttf']['url']}') format('truetype')";

Fatal error: [] operator not supported for strings in

Anything I missed code?

回答1:

You may have used this variable $w_custom_font1_src as a string somewhere else in the program.

So now reinitialize as an array

 $w_custom_font1_src =  array();


标签: php wordpress