1.2.837. No String With Append

PHP 7 doesn’t allow the usage of [] with strings. [] is an array-only operator.

This was possible in PHP 5, but is now forbidden in PHP 7.

<?php

$string = 'abc';

// Not possible in PHP 7
$string[] = 'd';

?>

See also class.

1.2.837.1. Suggestions

  • Use the concatenation operator . to append strings.

  • Use the concatenation short assignement .= to append strings.

1.2.837.2. Specs

Short name

Php/NoStringWithAppend

Rulesets

All, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56

Exakat since

0.8.4

PHP Version

With PHP 7.0 and more recent

Severity

Major

Time To Fix

Quick (30 mins)

Precision

Very high

Features

string, append

Available in

Entreprise Edition, Exakat Cloud