【问题标题】:Parse error: syntax error, unexpected '[' in whatsapp api with php 5.3解析错误:语法错误,使用 php 5.3 的 whatsapp api 中出现意外的“[”
【发布时间】:2016-03-28 10:55:07
【问题描述】:

我的脚本在我的 xampp php 5.6 版上运行良好。现在我尝试将它上传到服务器 php 版本 5.3.3 ,它说

PHP Parse error:  syntax error, unexpected '['

它嘲讽的是这一行:

$this->pending_nodes[$number] = [];

整个代码块如下所示:

public function addPendingNode(ProtocolNode $node){
  $from = $node->getAttribute("from");
  if(strpos($from,Constants::WHATSAPP_SERVER) !== false)
    $number = ExtractNumber($node->getAttribute("from"));
  else
    $number = ExtractNumber($node->getAttribute("participant"));

  if(!isset($this->pending_nodes[$number]))
    $this->pending_nodes[$number] = [];

  $this->pending_nodes[$number][] = $node;
}

感谢您的帮助,我无法通过谷歌搜索 [ 并且不知道它来自哪里,因为在 xampp 上它工作正常。

【问题讨论】:

  • 对于 5.3 试试这个 $this->pending_nodes['.$number.'] = [];
  • @DanyalSandeelo 你的建议会导致解析错误。
  • @tontonlayxx 我建议将 php 升级到 5.6 - 不支持 5.3 和 5.4; 5.5 已弃用:Supported Versions
  • 我也要升级我的服务器php版本@ash
  • 想升级* @ash

标签: php


【解决方案1】:

Short Array syntax was introduced in PHP 5.4 only

改变

$this->pending_nodes[$number] = [];

$this->pending_nodes[$number] = array();

upgrade to a PHP version that is not End of Life

【讨论】:

    猜你喜欢
    • 2013-04-27
    • 2019-01-16
    • 1970-01-01
    • 2015-03-09
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多