Fatal error: Uncaught Error: [] operator not supported for strings
Those who have switched from PHP 7.0 to PHP 7.1 or PHP 7.2 or PHP 7.3 will experience this issue. In our case the PHP version was 7.0 and we decided to upgrade PHP 7.3 version. As soon as we did the update we ran in to the following issue:
Fatal error: Uncaught Error: [] operator not supported for strings
It is the PHP language that has changed the empty index operator on a string from PHP 7.1 version. On PHP 7.0 or earlier version the string was silently converted to an array.
If we try to apply the empty index operator on string on PHP 7.1+ like below we get the above issue:
$username = ''; $username[] = 'Jenny'; // Uncaught Error: [] operator not supported for strings
The solution:
If we declare the variable as array instead of string like below then it solves the issue:
$username = array(); $username[] = 'Jenny';
If we are using WordPress slider revolution and we have upgraded the PHP version to 7.1 then it very likely we get this issue. It will throw an error for this line:
self::$arrMetaBoxes[] = $box; // Filename: base-admin.class.php
Because at the beginning of the class it was declared as string:
private static $arrMetaBoxes = '';
The solution in this case was:
private static $arrMetaBoxes = array();