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

查看:21
本文介绍了在 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->get('Config') 返回一个数组,我可以使用上面的代码在本地访问该数组,使用 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 在访问嵌套数组方面有什么不同吗?或者我有一些默认的 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天全站免登陆