This is just a limitation of PHP syntax. You cannot index the return value of a function if the function returns an array. There is nothing wrong with your function; rather, it indicates the homegrown nature of PHP. Like the catamari step, over time it became more functional and syntactic. This was not thought out from the very beginning, and this syntactic restriction is proof of this.
Similarly, even this simpler construction does not work:
// Syntax error echo array("one", "two", "three")[0];
To get around this, you must assign the result to a variable and then index the variable:
$array = get_arr(); echo $array[0];
Oddly enough, they correctly understood the objects. get_obj()->prop is syntactically valid and works as expected. Hover over your mouse.
source share