Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in accessing arrays in PHP 5.3 and 5.4 or some configuration mismatch?

I'm trying to access nested array element like this:

$dbSettings = $sm->get( 'Config' )[ 'doctrine' ][ 'connection' ][ 'orm_default' ][ 'params' ];

It's inside Module.php of Zend's framework 2 project. $sm->get('Config') return an array which I can access with code above locally, with PHP 5.4, while doing so on client's machine, it gives me an error:

Parse error: syntax error, unexpected '[' in /home/.../azk/module/Main/Module.php on line 121

Is there any difference in PHP 5.3 <=> 5.4 in accessing nested arrays or I have some default PHP configuration which is set differently on clients machne?

like image 839
kamil Avatar asked May 25 '13 15:05

kamil


1 Answers

Array dereferencing, which is what you are using, was introduced in PHP 5.4 and won't work in PHP 5.3.

So

$dbSettings = $sm->get( 'Config' )[ 'doctrine' ][ 'connection' ][ 'orm_default' ][ 'params' ];

Would need to be:

$dbSettings = $sm->get( 'Config' );
$params     = $dbSettings[ 'doctrine' ][ 'connection' ][ 'orm_default' ][ 'params' ];
like image 119
John Conde Avatar answered Sep 19 '22 01:09

John Conde