CakePHP的应用程序显示语法错误,意想不到的[ [英] CakePHP application displays Syntax error, unexpected [
问题描述
这是我收到的错误:
Error: syntax error, unexpected '['
Line: 10
我在Linux服务器上的Ubuntu 3.7上运行我的CakePHP的应用程序,它是CakePHP的2.3.7和5.3.1 PHP。 现在,我在安装Linux后,运行在EC2上WAMP。在我的LOCALMACHINE我在Windows 7上运行的XAMPP,并没有得到同样的错误。这是code其中显示了错误:
I'm running my cakephp app on a linux server ubuntu 3.7, it's cakephp 2.3.7 and PHP 5.3.1. Now, I'm running WAMP on EC2 after installing linux. On my localmachine I run XAMPP on Windows 7, and it does not get the same error. This is the code where it displays error:
10: <?php foreach ($this->Session->read('Customer')['Addresses'] as $key => $value) {
11: $ids[$z++] = $value['id'];
12: ?>
...
由于它不给任何错误的LOCALMACHINE,我猜想它有什么做的服务器环境。请帮帮忙,三江源! :)
Since it does not give any error on localmachine, I'm assuming it's got something to do with the server environment. Please help, Thankyou! :)
推荐答案
问题是在你的PHP版本。 PHP&LT; 5.4不接受的事情为 somefunction()['阵']
。
Problem is with your PHP version. PHP < 5.4 doesn't accept things as somefunction()['array']
.
该解决方案是分开的功能如
The solution would be to separate that function like
$customer = $this->Session->read('Customer');
foreach ($customer['Addresses'] as $key => $value) {
//etc
问题进行了说明,你可以找到<一href="http://stackoverflow.com/questions/18469032/cakephp-throws-an-error-unless-array-is-devided/18469382#18469382">another问题关于周围。
(PD:当然,另一个解决办法是PHP升级到5.4最少,但你需要牢记的迁移更改)
(PD: of course, other solution is to upgrade PHP to 5.4 at least, but you'll need to keep in mind the migration changes)
这篇关于CakePHP的应用程序显示语法错误,意想不到的[的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!