在php中替换`die()`

时间:2010-05-24 13:03:44

标签: php die

我有以下脚本

<?php
      echo "I am alive<br>";
      die("I am dying<br>");
      echo ("Dead");

?>

我得到的输出是

I am alive
I am dying

是否有任何方法(die()的替代/替代)继续执行剩余脚本?

编辑

抱歉,我得到了我想要的东西,并投票决定关闭这个问题。请忽略这个问题。

3 个答案:

答案 0 :(得分:6)

如果您的问题背后的动机在于错误处理,您可能需要查看PHP中的try / catch结构。

http://php.net/manual/en/language.exceptions.php

答案 1 :(得分:3)

您可以使用trigger_error

<?php
  echo "I am alive<br>";
  trigger_error("I am dying<br>");
  echo ("Dead");
?>

输出:

I am alive
Notice: I am dying in ... on line 3
Dead 

答案 2 :(得分:0)

如果要在将结果返回给用户后运行脚本,请尝试以下操作:

    while (ob_get_level () != 0) {
        ob_end_clean ();
    }

    header ("Connection: close\r\n");
    header ("Content-Encoding: none\r\n");
    ignore_user_abort (true);
    ob_start ();

    // do stuff that should be returned here

    header ("Content-Length: ".ob_get_length ());
    ob_end_flush ();
    flush ();

    // do rest here