14

PHP で同じオブジェクト内からオブジェクトを破棄する方法はありますか?

4

2 に答える 2

12

メソッドがオブジェクトのコンテキストで呼び出される場合、そのオブジェクトへの参照が少なくとも 1 つ必要です。PHP は到達不能オブジェクトのみを削除するため、答えはノーです。

于 2009-09-12T09:21:05.460 に答える
7

There is a way to self destruct an object :

Use the $GLOBALS array to find your instance in it, then use unset(). Be aware that unset() does not automatically call the __destruct() magic method all the time...

There is such a note in this way (see the unset() documentation) in the PHP documentation, but it does not explain exactly when unset() does not call the __destruct() method.

And I had this specific behaviour :

I do a :

unset($myInstance);
$myInstance = clone $otherInstance;

And the __constructor is called first, then the __destruct(). Or I would like the __destruct() to be called first because unset() is before clone... I ma stuck with that now...

Nicolas.

于 2010-08-02T19:33:19.250 に答える