代码之家  ›  专栏  ›  技术社区  ›  usoban

脚本终止时调用函数

php
  •  7
  • usoban  · 技术社区  · 16 年前

    我想在脚本被终止时调用函数 die() exit() .
    我的愿望是自动执行此操作,因此我不必一直调用函数。

    3 回复  |  直到 13 年前
        1
  •  17
  •   Scharrels    16 年前
        2
  •  4
  •   simonrjones    16 年前

    http://docs.php.net/manual/en/language.oop5.decon.php#language.oop5.decon.destructor

    在shutdown中运行脚本时需要记住的一点是,输出发送到浏览器后会发生这种情况,所以您不会在屏幕上显示任何错误。确保您记得将错误记录到文件中,以便关闭功能!

        3
  •  0
  •   uınbɐɥs Alex Reynolds    13 年前

    我不知道这是否有帮助,但你可以反过来做。

    定义如下所示的函数:

    function terminate() // you might want to have parameters here to handle different cases
    {
        the_function_to_call();
        die(); // or exit();
    }
    

    然后在代码调用中 terminate() 而不是 die() exit() .

    推荐文章