1.2.487. Function Subscripting, Old Style¶
It is possible use function results as an array, and read directly its element. This was added in PHP 5.4.
<?php
function foo() {
return array(1 => 'a', 'b', 'c');
}
echo foo()[1]; // displays 'a';
// Function subscripting, the old way
function foo() {
return array(1 => 'a', 'b', 'c');
}
$x = foo();
echo $x[1]; // displays 'a';
?>
1.2.487.1. Suggestions¶
Skip the local variable and directly use the return value from the function
1.2.487.2. Specs¶
Short name |
Structures/FunctionPreSubscripting |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
With PHP 5.4 and more recent |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
High |
Features |
function-subscripting |
Examples |
|
Available in |