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! 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.

First you have to enable Joomla! Debug modus, that’ll show you where the error is happening. Open up configuration.php and 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;

You can fix this PHP error by first initializing $data[] as an array:

$data = [];
$data[] = '<script type="text/javascript">' . NL;

A second method is to use the older style using array():

$data = array();
$data[] = '<script type="text/javascript">' . NL;

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.php

On line 150:

// $section_style         = '';
$section_style         = [];

WordPress Revolution Slider
Some (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;

Show your support


If you want to step in to help me cover the costs for running this website, that would be awesome. Just use this link to donate a cup of coffee ($5 USD for example). And please share the love and help others make use of this website. Thank you very much!

This may interest you:   Send authenticated email over TLS from Zen Cart

About the Author Jan Reilink

My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, websites & optimization.

follow me on:

Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of