duannian7116 2013-09-04 21:06
浏览 32
已采纳

CakePHP应用程序显示语法错误,意外[

This is the error I'm receiving:

Error: syntax error, unexpected '[' 
Line: 10

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:  ?>
...

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! :)

  • 写回答

2条回答 默认 最新

  • dtwncxs3547 2013-09-04 21:07
    关注

    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
    

    The problem is documented and you can find another questions regarding that around.

    (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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序