[] operator not supported for strings

Description

Strings and array share the bracket operator for accessing individual elements, but the append operator [] is not supported for strings.

Example

<?php

$string = 'abc';
$string[] = 'b';

?>

Solutions

  • Use the . operator to add a string at the end of another.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.