开发者

get the exit message to use it with an object's __destruct method

$fooinstance = new foo();
/*do something*/
exit('bar');

class foo{
  __destruct(){
    //get the exit message ("bar") to do something with it
  }
}

Hello,

I would like to get th开发者_运维百科e exit message to do something with it (for example insert the exit status in a database). Is there a way to do that ?

Thanks


The text exit sends isn't special; it's just text that's output before the script dies.

You could get the text with output buffering, though I'm not sure it'll be useful:

<?php
$fooinstance = new foo();
ob_start();
exit('bar');

class foo{
  function __destruct(){
    $c = ob_get_contents(); //$c is "bar"
  }
}

It would probably be best to wrap the exit instruction in a function that did the appropriate logging.


This is an incorrect way to do things. Why do you need this particular solution?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜