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


GamesGames

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:

$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)
foto van Jan Reilink

About the author

Hi, my name is Jan. I am not a hacker, coder, developer or guru. I am merely a systems administrator, doing my daily SysOps/DevOps thing at cldin. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, websites & optimization.

0 0 votes
Article Rating
Subscribe
Notify of
52 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Jack
1 year ago

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

2 years ago

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

Marc
2 years ago

Thank you!

JC
3 years ago

HUGE THANKS ! :)

Juan Alejandro Opayome
3 years ago

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.

Reply to  Juan Alejandro Opayome
2 years ago

Yes, This worked for me too.

3 years ago

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

3 years ago

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

Lydia
3 years ago

Thanks !

3 years ago

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;
}

Janus Allen Capili
3 years ago

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!

Paul Schmidt
3 years ago

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

Jak
3 years ago

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.

Adri
Reply to  Jak
3 years ago

Perfecto!!!, adios al error. Muchísimas gracias.

3 years ago

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;

3 years ago

Sounds Good, but the I put the debug to 1 in my configuration.php but dont show me what is line number

Reply to  Jan Reilink
3 years ago

Thank you so much.. this work for me!

3 years ago

THANK YOU SOOO MUCCHHHH!! Perfect SOLUTION!!

3 years ago

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!

Flo Sokol
3 years ago

I changed public $debug to ‘1’ but it still only shows the original error (“[] operator not supported for strings”). What can I do?

Alejandro Ferguson
3 years ago

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.

Wordpress Hostage
3 years ago

HERO! Thanks for this post. IT WORKED!

fahadali
3 years ago

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??

Walter Munoz
4 years ago

Dude!!! Thank you!!!

Dustin
4 years ago

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

Magda
4 years ago

Yay, it worked like a charm for my REV slider.

Thanks!

poggio del falco
4 years ago

we need help about this error :
Errore fatale: Errore non rilevato: [] operatore non supportato per archi in /home/cartepre/addon_domains/poggiodelfalco.com/wp-content/plugins/revslider/inc_php/framework/base_admin.class.php:73 traccia stack: # 0 / home / cartepre / addon_domains / poggiodelfalco.com / wp-content / plugins / revslider / revslider_admin.php (237) UniteBaseAdminClassRev :: addMetaBox ( ‘rivoluzione Fatto scorrere …’, Object (UniteSettingsAdvancedRev), Array, NULL) # 1 / home / cartepre / addon_domains / poggiodelfalco.com / wp-content / plugins / revslider / revslider_admin.php (68) RevSliderAdmin-> addSliderMetaBox () # 2 /home/cartepre/addon_domains/poggiodelfalco.com/wp-content/plugins/revslider/ revslider_admin.php (40): RevSliderAdmin-> init () # 3 /home/cartepre/addon_domains/poggiodelfalco.com/wp-content/plugins/revslider/revslider.php(147) RevSliderAdmin -> __ construct ( ‘/ home / cartepre / … ‘) # 4 /home/cartepre/addon_domains/poggiodelfalco.com/wp-settings.php(305): include_once ( ‘/ home / cartepre / …’) # 5 /home/cartepre/addon_domains/poggiodelfalco.com/wp -config.php (95): require_once (‘/ home / cartepre / in/home/cartepre/addon_domains/poggiodelfalco.com/wp-content/plugins/revslider/inc_php/framework/base_admin.class.php on line 73

poggio del falco
4 years ago

Good evening this is our error :
Fatal error: Uncaught Error: [] operator not supported for strings in /home/cartepre/addon_domains/poggiodelfalco.com/wp-content/plugins/revslider/inc_php/framework/base_admin.class.php:73 Stack trace: #0 /home/cartepre/addon_domains/poggiodelfalco.com/wp-content/plugins/revslider/revslider_admin.php(237): UniteBaseAdminClassRev::addMetaBox(‘Revolution Slid…’, Object(UniteSettingsAdvancedRev), Array, NULL) #1 /home/cartepre/addon_domains/poggiodelfalco.com/wp-content/plugins/revslider/revslider_admin.php(68): RevSliderAdmin->addSliderMetaBox() #2 /home/cartepre/addon_domains/poggiodelfalco.com/wp-content/plugins/revslider/revslider_admin.php(40): RevSliderAdmin->init() #3 /home/cartepre/addon_domains/poggiodelfalco.com/wp-content/plugins/revslider/revslider.php(147): RevSliderAdmin->__construct(‘/home/cartepre/…’) #4 /home/cartepre/addon_domains/poggiodelfalco.com/wp-settings.php(305): include_once(‘/home/cartepre/…’) #5 /home/cartepre/addon_domains/poggiodelfalco.com/wp-config.php(95): require_once(‘/home/cartepre/ in /home/cartepre/addon_domains/poggiodelfalco.com/wp-content/plugins/revslider/inc_php/framework/base_admin.class.php on line 73
We cann’t enter on my sites on WordPress.
Can you hel us?

David
4 years ago

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?

jefferson
4 years ago

thank you very much

Nicolas PLOQUIN
4 years ago

Many thanks! :)

Sam Torres
4 years ago

Total lifesaver given our host has forced to update to PHP 7.2! Thank you!

Venkatesha K
4 years ago

Thanks a lot.
saved my day.

very easy and understanding guidance.

Pia Jensen
4 years ago

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

Sushil A.
4 years ago

Thanks! You saved my day!

4 years ago

Thanks a ton!! That did the trick!!

Magnus
4 years ago

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.

andy
4 years ago

Legend, that fixed it :)

52
0
Would love your thoughts, please comment.x
()
x