Sysadmins of the North

Technical blog, where topics include: computer, server, web, sysadmin, MySQL, database, virtualization, optimization and security

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:

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

Want to say thanks?

If I’ve helped you out and you want to thank me, why not buy me a coffee?

If I’ve helped you out and you want to thank me, why not buy me a coffee?

Thank you for your support. ♥

Previous

Windows Server 2016 on Hyper-V stuck at stopping

Next

A plea for WordPress plugin developers to stop supporting legacy PHP versions

9 Comments

  1. Sam Torres

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

  2. Venkatesha K

    Thanks a lot.
    saved my day.

    very easy and understanding guidance.

  3. Pia Jensen

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

  4. Sushil A.

    Thanks! You saved my day!

  5. Thanks a ton!! That did the trick!!

  6. Magnus

    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.

  7. andy

    Legend, that fixed it 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered by WordPress & Theme by Anders Norén

15 queries, 0.267 seconds running PHP version 7.3.0