Connecting Tech Pros Worldwide Help | Site Map

explicitly destroy Objects in PHP5

Thomas Ilsche
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi,

how do I "explicitly destroy" an Object in PHP5 to make sure the
destructor is called an the object destroyed?

unset is not an option because there are multiple variables containing
the object handle.

Waiting for the end of the script is aswell a bad option because the
order in which the destructores are called does matter.

So what else could be done to "explicitly destroy" the object?
If i simply call __destruct it would be called twice, bad aswell.

Since I have intensively searched the manual I fear there is no C++
like "delete Obj" construct in PHP. I really wonder why this is not
the case since destructors exist and the other OOP features of PHP5
seem really fine.

Any Ideas?

Best Regards
Thomas Ilsche
Wayne
Guest
 
Posts: n/a
#2: Jul 17 '05

re: explicitly destroy Objects in PHP5


On 18 Apr 2005 07:01:01 -0700, google@zulan.net (Thomas Ilsche) wrote:
[color=blue]
>how do I "explicitly destroy" an Object in PHP5 to make sure the
>destructor is called an the object destroyed?[/color]

Remove all references to the object.
[color=blue]
>unset is not an option because there are multiple variables containing
>the object handle.[/color]

If you were to explicitly destroy the object than these multiple
variables would reference a destroyed object -- that would not be a
good thing.

The best option is still to remove all the references.
[color=blue]
>So what else could be done to "explicitly destroy" the object?
>If i simply call __destruct it would be called twice, bad aswell.[/color]

Use a flag to prevent __destruct from doing anything more the second
time it's called. What is going on in your destructor anyway?
[color=blue]
>Since I have intensively searched the manual I fear there is no C++
>like "delete Obj" construct in PHP. I really wonder why this is not
>the case since destructors exist and the other OOP features of PHP5
>seem really fine.[/color]

C++ doesn't have garbage collection which is why it has delete. PHP
has garbage collection so delete isn't needed.


Closed Thread