开发者

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

开发者 https://www.devze.com 2023-01-11 14:10 出处:网络
$fooinstance = new foo(); /*do something*/ exit(\'bar\'); class foo{ __destruct(){ //get the exit message (\"bar\") to do something with it
$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

精彩评论

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

关注公众号