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?
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' ];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With