【问题标题】:Parse error: syntax error, unexpected T_STRING in line [closed]解析错误:语法错误,行中的意外 T_STRING [关闭]
【发布时间】:2013-01-02 13:44:10
【问题描述】:

当我尝试使用 cron 作业运行文件时,我得到以下信息

Parse error: syntax error, unexpected T_STRING in /home/joshand2/public_html/application/models/model_posting.php on line 1787

1787 中的行是goto endofloop; 我不知道这行是否有任何语法相关的问题,但endofloop 指的是。

结束循环:

if (file_exists("cookies/".$this->job_id."_job_".$this->site_id."_site.txt")) {
    echo "The file cookies/".$this->job_id."_job_".$this->site_id."_site.txt exists"; 
    unlink("cookies/".$this->job_id."_job_".$this->site_id."_site.txt");
}

谁能帮我解决这个错误?

【问题讨论】:

  • 发布更多代码,提供的代码中没有错误
  • 可能您使用的 PHP 版本不支持 goto (goto。 imgs.xkcd.com/comics/goto.png
  • 由 php.net 提供:php.net/manual/en/images/…
  • @DaveRandom - 是否有任何替代关键字代替 goto?
  • @lock 函数。或面向对象编程。

标签: php parse-error


【解决方案1】:

您可能需要重构代码以避免使用goto 跳转标签。

因为:

  1. 听起来好像您的 PHP 版本可能还不支持它(DaveRandom 建议的版本
  2. 可能有一种方法可以避免跳转标签并仍然实现相同的行为

【讨论】:

  • +1 嗨goto,再见goto :(
【解决方案2】:

不要使用 goto。至少定义一个函数。您的代码示例如下:

function endOfLoop($job_id, $site_id) {
    $file = 'cookies/' . $job_id . '_job_' . $site_id . '_site.txt';
    if (file_exists($file)) {
        echo 'The file ' . $file . ' exists'; 
        unlink($file);
    }
}

然后在你使用 goto 的地方,只需调用你的函数:

endOfLoop($this->job_id, $this->site_id);

您将某些东西标记为“endofloop”这一事实肯定表明您需要重新考虑您的代码。

【讨论】:

    猜你喜欢
    • 2013-05-13
    • 1970-01-01
    • 2014-08-09
    • 2013-07-15
    • 2015-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多