差异在PHP 5.3和5.4或者一些配置不匹配访问数组? [英] Difference in accessing arrays in PHP 5.3 and 5.4 or some configuration mismatch?

查看:201
本文介绍了差异在PHP 5.3和5.4或者一些配置不匹配访问数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问嵌套的数组元素是这样的:

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

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

这里面 Zend的框架2项目Module.php $ SM->获取('配置')返回,我可以用code使用上述局部,使用PHP 5.4的数组,而客户机上这样做,它给了我一个错误:

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

有没有在PHP 5.3 - 的任何区别;在访问嵌套数组=> 5.4或我有上设置不同的客户machne一些默认的PHP配置

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?

推荐答案

阵列提领,这是你使用的是什么,在PHP 5.4中引入的,不会在PHP 5.3工作。

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

所以

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

将需要:

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

这篇关于差异在PHP 5.3和5.4或者一些配置不匹配访问数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆