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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化