__destruct()销毁包含对另一个对象的引用的对象 [英] __destruct() destroy an object that contains a reference to another object
问题描述
我正在使用PHP 5.1
我有两个对象,第二个是先使用
的实例。 />
如下例所示,即使第二个
包含引用,垃圾收集器也会在第二个类之前调用第一个类的
destruct方法到了另一个,所以我不能完成所有的b $ b操作,没有全部可用的代码!
谢谢
例如:
class MyFirstClass
{
公共功能__construct()
{
...操作......
}
公共功能__destruct()
{
echo" Destroyed MyFirstClass" ;;
}
}
class MySecondClass
{
private $ obj = NULL
公共函数__construct($ obj)
{
...操作......
}
公共功能__destruct()
{
echo" Destroyed MySecondClass" ;;
}
}
$ obj1 = new MyFirstClass();
$ obj2 = new MySecondClass($ obj1);
//结果
//销毁MyFirstClass
//销毁MySecondClass
obj = NULL
公共函数__construct(
obj)
{
...操作...... < br $>
}
公共函数__destruct()
{
echo" Destroyed MySecondClass";
}
}
obj1 = new MyFirstClass();
Hi, i''m using PHP 5.1
I have two objects and the second one is using an instance of the
first.
As displayed in the example below, the Garbage Collector calls the
destruct method of the first class before the second even if the second
contains a reference to the other, so i can''t complete all the
operations not having all "the code available"!
Thank you
Ex.:
class MyFirstClass
{
public function __construct()
{
... operations...
}
public function __destruct()
{
echo "Destroyed MyFirstClass";
}
}
class MySecondClass
{
private $obj = NULL
public function __construct($obj)
{
... operations...
}
public function __destruct()
{
echo "Destroyed MySecondClass";
}
}
$obj1 = new MyFirstClass();
$obj2 = new MySecondClass($obj1);
// Result
// Destroyed MyFirstClass
// Destroyed MySecondClass
obj = NULL
public function __construct(
obj)
{
... operations...
}
public function __destruct()
{
echo "Destroyed MySecondClass";
}
}
obj1 = new MyFirstClass();
这篇关于__destruct()销毁包含对另一个对象的引用的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!