1.2.346. Dereferencing String And Arrays

PHP allows the direct dereferencing of strings and arrays, from array literals and returned array.

This was added in PHP 5.5. There is no need anymore for an intermediate variable between a string and array (or any expression generating such value) and accessing an index.

<?php
$x = array(4,5,6);
$y = $x[2] ; // is 6

//May be replaced by
$y = array(4,5,6)[2];
$y = [4,5,6][2];
?>

1.2.346.1. Specs

Short name

Structures/DereferencingAS

Rulesets

All, Appinfo, CE, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54

Exakat since

0.8.4

PHP Version

With PHP 5.3 and older

Severity

Major

Time To Fix

Quick (30 mins)

Precision

Very high

Features

dereferencing

Available in

Entreprise Edition, Community Edition, Exakat Cloud