$fooinstance = new foo();
/*do something*/
exit('bar');
class foo{
__destruct(){
//get the exit message ("bar") to do something with it
}
}
您好,
我想获取退出消息以对其执行某些操作(例如,将退出状态插入数据库中)。有没有办法做到这一点?
由于
答案 0 :(得分:1)
exit
发送的文字并不特别;它只是text that's output before the script dies。
你可以通过输出缓冲来获取文本,但我不确定它是否有用:
<?php
$fooinstance = new foo();
ob_start();
exit('bar');
class foo{
function __destruct(){
$c = ob_get_contents(); //$c is "bar"
}
}
最好将exit指令包装在执行相应日志记录的函数中。
答案 1 :(得分:0)
这是一种不正确的做事方式。为什么需要这个特定的解决方案?