You are here: Saotn.org » Code base » Fatal error: Uncaught Error: [] operator not supported for strings – PHP 7.1

# Fatal error: Uncaught Error: [] operator not supported for strings – PHP 7.1

With PHP 7.1, some PHP web applications fail because of deprecated code usage. This may result in an error message like [] operator not supported for strings for various Joomla, WordPress and Drupal components. Here’s how to fix this code for PHP 7.1+.

I’ll use Joomla as an example in this short post. The same error and fix may apply for other CMS systems like WordPress and Drupal.

First you have to enable Joomla Debug modus, that’ll show you where the error is happening. Open up configuration.php and set public debug to 1. If you refresh the page now, you’ll see Joomla’s error page, telling you about Fatal error: Uncaught Error: Fatal error: Uncaught Error: [] operator not supported for strings D:\www\example.com\www\components\com_layer_slider\base\includes\slider_markup_init.php:98 OK, so we now know where the error is, it’s on line 98 in com_layer_slider’s base\includes\slider_markup_init.php file. In this case, the failing code is: .wp-block-code { border: 0; padding: 0; } .wp-block-code > div { overflow: auto; } .shcb-language { border: 0; clip: rect(1px, 1px, 1px, 1px); -webkit-clip-path: inset(50%); clip-path: inset(50%); height: 1px; margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px; word-wrap: normal; word-break: normal; } .hljs { box-sizing: border-box; } .hljs.shcb-code-table { display: table; width: 100%; } .hljs.shcb-code-table > .shcb-loc { color: inherit; display: table-row; width: 100%; } .hljs.shcb-code-table .shcb-loc > span { display: table-cell; } .wp-block-code code.hljs:not(.shcb-wrap-lines) { white-space: pre; } .wp-block-code code.hljs.shcb-wrap-lines { white-space: pre-wrap; } .hljs.shcb-line-numbers { border-spacing: 0; counter-reset: line; } .hljs.shcb-line-numbers > .shcb-loc { counter-increment: line; } .hljs.shcb-line-numbers .shcb-loc > span { padding-left: 0.75em; } .hljs.shcb-line-numbers .shcb-loc::before { border-right: 1px solid #ddd; content: counter(line); display: table-cell; padding: 0 0.75em; text-align: right; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; white-space: nowrap; width: 1%; } data = '<script type="text/javascript">' . NL;Code language: PHP (php)

You can fix this PHP error by first initializing $data[] as an array: $data = [];
$data[] = '<script type="text/javascript">' . NL;Code language: PHP (php) A second method is to use the older style using array(): $data = array();
$data[] = '<script type="text/javascript">' . NL;Code language: PHP (php) Let’s hope not too many Joomla components, plugins and extensions use code like this. Not to mention other CMS systems like Expression Engine, WordPress, BuddyPress, PrestaShop… Update 3-3-2018: WordPress premium Betheme theme by Muffin group needs a fix in the file wp-content\themes\betheme\functions\builder\front.phpCode language: PHP (php) On line 150: //$section_style         = '';
$section_style = [];Code language: PHP (php) WordPress Revolution Slider Older versions of WordPress plugin Revolution Slider by ThemePunch has this same deprecated PHP code, and throws an error: Uncaught Error: [] operator not supported for strings in wp-content\plugins\revslider\includes\framework\base-admin.class.php:69 To fix this, add a line before line 69: self::$arrMetaBoxes = []; # add this line to create the variable as an array
self::$arrMetaBoxes[] =$box;Code language: PHP (php)

### 52 thoughts on “Fatal error: Uncaught Error: [] operator not supported for strings – PHP 7.1”

1. Thank you. The Revolution Slider fix your article suggested worked perfectly for me using PHP 7.4 (upgraded from 7.0).

2. Wow,
After searching a lot of StackOverflow tutorial and finally your suggestions work well.
I have fixed my array issue.
Thanks a lot.

3. Juan Alejandro Opayome

Wow this part worked for me:

self::$arrMetaBoxes = []; # add this line to create the variable as an array self::$arrMetaBoxes[] = $box; I had the same issue on revolution slider. 4. I am getting these errors – Fatal error: Uncaught Error: [] operator not supported for strings in C:\xampp\htdocs\wordpress\wp-content\plugins\revslider\includes\framework\base-admin.class.php:71 Stack trace: #0 C:\xampp\htdocs\wordpress\wp-content\plugins\revslider\admin\revslider-admin.class.php(572): RevSliderBaseAdmin::addMetaBox(‘Revolution Slid…’, ”, Array, NULL) #1 C:\xampp\htdocs\wordpress\wp-content\plugins\revslider\admin\revslider-admin.class.php(73): RevSliderAdmin->addSliderMetaBox() #2 C:\xampp\htdocs\wordpress\wp-content\plugins\revslider\admin\revslider-admin.class.php(44): RevSliderAdmin->init() #3 C:\xampp\htdocs\wordpress\wp-content\plugins\revslider\revslider.php(164): RevSliderAdmin->__construct(‘C:\\xampp\\htdocs…’) #4 C:\xampp\htdocs\wordpress\wp-admin\includes\plugin.php(2141): include(‘C:\\xampp\\htdocs…’) #5 C:\xampp\htdocs\wordpress\wp-admin\plugins.php(175): plugin_sandbox_scrape(‘revslider/revsl…’) #6 {main} thrown in C:\xampp\htdocs\wordpress\wp-content\plugins\revslider\includes\framework\base-admin.class.php on line 71 5. sir your website is so much useful for me i do thousand of ways but i cant find the solution but after visiting your site i got solution keep doing this i appreciate you 6. Magento 1.9 Webshopapps Matrix Pro module has this problem too. For fixing it edit the file app/code/community/Webshopapps/Wsacommon/Helper/Shipping.php, line 312: } else {$itemGroup = [];
$itemGroup[] =$item;
}

7. Janus Allen Capili

Very helpful and informative! One of the sites I’ve been administering has a revslider plugin. The wordpress site uses an older version of PHP. Thus, when I tried to transfer the files on my localhost that has the new version of PHP, it stumbled upon this issue.

This article helped me to resolve the issue on the plugin and the site is working as expected. Thank you!

8. Great work, this saved me much time fixing some errors on an WordPress page.

9. Thanks – this:
// $section_style = ”;$section_style = [];

also worked for the Rocco theme by MuffinGroup (for the benefit of anyone else getting to this via the Googles…) the error is thrown by rocco/functions/meta-functions.php on line 1579.

10. You can fix the error by adding this line before line 71:
if(!is_array(self::$arrMetaBoxes)) self::$arrMetaBoxes = array();

It should stay like this on line 71 and 72:
if(!is_array(self::$arrMetaBoxes)) self::$arrMetaBoxes = array();
self::$arrMetaBoxes[] =$box;

1. Hi David,
The reason you don’t see the line number might be because of PHP’s error_reporting() settings, or .htaccess. Check your php.ini and .htaccess files and/or ask your hosting provider. Perhaps add error_reporting = E_ALL and display_errors = On to your user-defined ini or the proper php_flag to your .htaccess.

11. What are the chances one of the first Google results for a generic error would have the answer for the specific theme and plugin giving me issues?! Thanks so much!

12. I changed public $debug to ‘1’ but it still only shows the original error (“[] operator not supported for strings”). What can I do? 13. Alejandro Ferguson Gracias! it works beautifully!! i found the file to modify on this path: /wp-content/plugins/revslider/inc_php/framework i love you man or woman whatever. 14. Fatal error: Uncaught Error: [] operator not supported for strings in C:\wamp64\www\project\wp-content\plugins\revslider\inc_php\framework\base_admin.class.php on line 72 how to solve this error?? 15. The Rev Slider update worked perfectly, but I also have the Betheme and I can’t get the code change to help. Here’s the error I’m getting on Kellermandental.com: Fatal error: Uncaught Error: [] operator not supported for strings in /home/kellerma/public_html/wp-content/themes/betheme/functions/builder/front.php:144 Stack trace: #0 /home/kellerma/public_html/wp-content/themes/betheme/page.php(24): mfn_builder_print(47) #1 /home/kellerma/public_html/wp-includes/template-loader.php(77): include(‘/home/kellerma/…’) #2 /home/kellerma/public_html/wp-blog-header.php(19): require_once(‘/home/kellerma/…’) #3 /home/kellerma/public_html/index.php(17): require(‘/home/kellerma/…’) #4 {main} thrown in /home/kellerma/public_html/wp-content/themes/betheme/functions/builder/front.php on line 144 I added your extra code to Line 143 but it didn’t fix it. Here’s what that section has now: 141 // styles ————————- 142$section_style = ”;
143 $section_style = []; 144$section_style[] = ‘padding-top:’. intval( $section[‘attr’][‘padding_top’] ) .’px’; Any other help? Thanks! Dusti 1. Hi Dustin, Great to hear the Rev Slide fix/update worked perfectly. For BeTheme (of which I don’t have a copy available), I’d comment out line 142 in wp-content/themes/betheme/functions/builder/front.php: //$section_style ='';

If that fails I recommend you contact the theme authors for a fix.

16. poggio del falco

1. If you can’t make the changes yourself, using the information from this blog post, then you can either ask your web hosting provider, and/or pursue the FTP option I mentioned. I can’t help you from here unfortunately.

17. poggio del falco

Good evening this is our error :
We cann’t enter on my sites on WordPress.
Can you hel us?

1. The fastest way is to disable the plugin entirely, for example by FTP (rename the directory). Then install a new version of the revslider plugin.

The second option involves making code changes to revslider/inc_php/framework/base_admin.class.php as described in this post. What changes, and where, depends on your revslider plugin version. Try to match your file around line 73 with the code examples from this blog post.

But as said, option #1 is the most simple: use FTP to rename or delete the plugin file, log on and install a new version.

Goodluck!

18. Hi, I tried the revslider edit – self::$arrMetaBoxes[] =$box; – mine was on line 71. I added – self::$arrMetaBoxes = []; – above like you instructed, but I’m getting a syntax error. Could it be because on line 65 –$box = array(); – it already is labeled an array?

1. Hi David,
The solution -code fix- may differ per revslider version. What does your complete error message look like?

Recently one of our clients had the following error in Revolution Slider 4.6.5:

Fatal error: Uncaught Error: [] operator not supported for strings in d:\sites\path\to\website\www\wp-content\plugins\revslider\inc_php\framework\base_admin.class.php:72
#6 {main} thrown in d:\sites\path\to\website\www\wp-content\plugins\revslider\inc_php\framework\base_admin.class.php on line 72

Because of this error he couldn’t log on into the WordPress Dashboard. I used the same code fix as in this post, after which he could log on again. Then we updated Revolution Slider by FTP because of other errors.

19. Thank you!
Having very little experience with fixing PHP errors this was a great guide – my issue was with the Revslider in WP.

20. Thank you a million times and if I could I would give you a really big hug!
Drove me crazy trying to to fix the login since we were locked out of our site and we really needed to switch a few things around asap.

“WordPress Revolution Slider
Older versions of Revolution Slider plugin by ThemePunch has this same deprecated PHP code, and throws an error:

Uncaught Error: [] operator not supported for strings in wp-content\plugins\revslider\includes\framework\base-admin.class.php:69
To fix this, add a line before line 69:

self::$arrMetaBoxes = []; # add this line to create the variable as an array self::$arrMetaBoxes[] = \$box;

Thank you once again and bookmarked for future reference.