row_array()['key'] doesn't work in PHP

2020-04-19 23:51发布

问题:

Am I right that the following syntax works in PHP 5.4 but doesn't work in PHP 5.3?

$users[$key]['class'] = $class->row_array()['name'];

The row_array() function is a CodeIgniter function which returns an array. I was stumbled when I found out that none of my code worked when I moved it to the live server, this is very frustrating of course because now I'll have to refactor everything.

Can anyone please tell me if this is related to the PHP version and if there is a possible easier solution rather than refactoring everything?

回答1:

Array dereferencing has been introduced in PHP5.4

As of PHP 5.4 it is possible to array dereference the result of a function or method call directly. Before it was only possible using a temporary variable.

http://php.net/manual/en/language.types.array.php