【问题标题】:PHP problem with die()die() 的 PHP 问题
【发布时间】:2011-02-22 12:45:09
【问题描述】:

所以,我有这个代码:

        } else {

            $photograph_moderation = new PhotographModeration($this->photograph_id);
            $photograph_moderation->purgePhotograph();

            //eventually take to an error page
            die('image is not big enough to upload');

        }

purgePhotograph() 函数在满足此条件时被正确调用,但脚本似乎永远不会死掉。有没有理由不在这里调用死? purgePhotograph() 也没有脚本杀戮命令。

这里是 purge_photograph 函数:

public function purgePhotograph() {

    $db = Connect::connect();
    $photograph_id = $db->real_escape_string($this->photograph_id);

    $query = "SELECT * from photographs WHERE id='{$this->photograph_id}'";
    $result = $db->query($query);
    $photograph = $result->fetch_assoc();

    if ($photograph['location'])
    unlink($photograph['location']);

    if ($photograph['thumbnail_location'])
    unlink($photograph['thumbnail_location']);

    if ($photograph['watermark_location'])
    unlink($photograph['watermark_location']);

    if ($photograph['xsmall_location'])
    unlink($photograph['xsmall_location']);

    if ($photograph['small_location'])
    unlink($photograph['small_location']);

    if ($photograph['medium_location'])
    unlink($photograph['medium_location']);

    if ($photograph['large_location'])
    unlink($photograph['large_location']);

    if ($photograph['xlarge_location'])
    unlink($photograph['xlarge_location']);

    if ($photograph['xxlarge_location'])
    unlink($photograph['xxlarge_location']);

    if ($photograph['xxxlarge_location'])
    unlink($photograph['xxxlarge_location']);

    $query = "DELETE from photographs WHERE id='{$this->photograph_id}'";
    $result = $db->query($query);

    $query = "DELETE from photograph_tags WHERE photograph_id='{$this->photograph_id}'";
    $result = $db->query($query);

}

【问题讨论】:

  • 您是否真的尝试过仅使用您提供的三行代码,中间没有 eventually 的东西?
  • 我从未见过 die() 失败。是什么让您如此确定 purgePhotograph() 会退出?
  • @Anthony:我认为这是一个 TODO 评论,如,最终用错误页面替换 die :-)
  • 仅供参考,您那里有一个 SQL 注入漏洞。在 SQL 内部,它应该是 WHERE id = {$photograph_id} 而不是 $this->photograph_id...
  • @Josh:是的,这是一条 TODO 评论;仅使用 die 进行测试

标签: php die


【解决方案1】:

检查 purgePhotograph() 是否返回。也许它有一个死循环或需要很长时间。

【讨论】:

  • 或者只是将其注释掉,然后看看 die 是否有效。如果是这样,您知道问题出在purgePhotograph()
【解决方案2】:

也许现在是安装php debugger module 并进入相关代码的时候了。
xdebug 和例如netbeans 作为前端运行良好。

【讨论】:

    【解决方案3】:

    哇,问题是 purgePhotograph() 从来没有返回 1;在末尾。我不知道这是执行以下行所必需的。

    【讨论】:

    • “我不知道这是执行以下行所必需的。”它不是。很多 PHP 内置函数没有返回语句(在 PHP 手册中也称为返回 void),并且继续正常执行。这可能表明存在其他问题。
    • 这不是必需的。还有一些其他问题,你一定是无意中解决的。顺便说一句:请务必查看我对主线程的评论...
    • 语句都正常完成,我只是把它们放在条件中并测试了每一个
    • 你检查过错误日志吗?会不会是 WSOD(白屏死机)?
    【解决方案4】:

    尝试将其放入 try/catch 块中。 也许在 die 可以被执行之前有什么东西抛出了异常。

    你有什么错误吗?

    【讨论】:

      猜你喜欢
      • 2011-08-15
      • 2021-11-21
      • 2010-10-27
      • 1970-01-01
      • 2011-04-20
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 2012-07-03
      相关资源
      最近更新 更多