关机顺序 [英] Shutdown order

查看:100
本文介绍了关机顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有这个代码:


class Test

{

public $ status =''dead'';

function __construct(){$ this-> status =''alive''; }

函数__destruct(){echo''< br> __ destruct()''; }

}

$ o =新测试;


函数关闭()

{

echo''< br> shutdown()'';

}

register_shutdown_function(''shutdown'');


功能obflush($ s)

{

全球$ o;

返回$ s。 ''< br> obflush()''。 $ o->状态;

}

ob_start(''obflush'');


哪个(使用PHP 5.1) .4)产生这个输出:


关闭()

__destruct()

obflush()活着


我有两个问题:


1)我已经读过这三个函数被调用的顺序

之前已经改变了在未来的PHP版本中可能会再次发生变化。

这是否意味着我完全不能依赖这个订单?


2)为什么是$ o仍然是活着的在obflush()中,即使它的析构函数之前已被调用过吗?已经调用了析构函数,我希望全局$ o

指向不再存在的变量(因此,null)。


问候,

Thomas

Hi,

I have this code:

class Test
{
public $status = ''dead'';
function __construct() { $this->status = ''alive''; }
function __destruct() { echo ''<br>__destruct()''; }
}
$o = new Test;

function shutdown()
{
echo ''<br>shutdown()'';
}
register_shutdown_function(''shutdown'');

function obflush( $s )
{
global $o;
return $s . ''<br>obflush() '' . $o->status;
}
ob_start(''obflush'');

Which (using PHP 5.1.4) produces this output:

shutdown()
__destruct()
obflush() alive

I have two questions:

1) I have read that the order in which the three functions are called has
changed previously and is likely to change again in future versions of PHP.
Does this mean I cannot rely on this order at all?

2) Why is $o still "alive" in obflush() even though its destructor has been
called before? The destructor having been called, I would expect global $o
to point to a no longer existing variable (thus, "null").

Greetings,
Thomas

推荐答案

status =''dead'';

function __construct( ){
status = ''dead'';
function __construct() {


this-> status =''alive''; }

函数__destruct(){echo''< br> __ destruct()''; }

}
this->status = ''alive''; }
function __destruct() { echo ''<br>__destruct()''; }
}


o =新测试;


函数shutdown()

{

echo''< br> shutdown()'';

}

register_shutdown_function(''shutdown'' );


函数obflush(
o = new Test;

function shutdown()
{
echo ''<br>shutdown()'';
}
register_shutdown_function(''shutdown'');

function obflush(


这篇关于关机顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆