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 VMware安装虚拟网络驱动程序不成功,如何解决?(操作系统-linux)
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码
  • ¥400 微信停车小程序谁懂的来
  • ¥15 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥15 QFILHelper怎么恢复全字库,提示进程已完成,只能恢复分区文件