3D Realms Forums

3D Realms Forums (https://forums.3drealms.com/vb/index.php)
-   Programming Forum (https://forums.3drealms.com/vb/forumdisplay.php?f=24)
-   -   Quick PHP5 question - Object self-destruct (https://forums.3drealms.com/vb/showthread.php?t=25769)

Foxy 03-07-2007 06:19 AM

Quick PHP5 question - Object self-destruct
 
Is there any way to make an object destroy itself in PHP5? I'd like to have some objects kill themselves after they're 'used' so that they cannot be reused (which would cause issues).

Phait 03-07-2007 07:00 AM

Re: Quick PHP5 question - Object self-destruct
 
Try http://www.faqts.com/knowledge_base/index.phtml/fid/51

Foxy 03-07-2007 12:40 PM

Re: Quick PHP5 question - Object self-destruct
 
Nothing there.

Phait 03-07-2007 12:45 PM

Re: Quick PHP5 question - Object self-destruct
 
Try http://www.phpbuilder.net forums

AlienAssKicker 03-08-2007 08:18 PM

Re: Quick PHP5 question - Object self-destruct
 
Can't you explicitly call the __destruct() function?

Foxy 03-09-2007 05:35 AM

Re: Quick PHP5 question - Object self-destruct
 
Doubt that'll destruct it. As I understand it __destruct is something called by PHP when it actually blows the object away to let you clean up.

Black Yeti 04-02-2007 07:02 PM

Re: Quick PHP5 question - Object self-destruct
 
AFAIK you cannot explicitly destroy objects in php. They are automatically destroyed as soon as there are no more references pointing to it. Destroying objects while there are references pointing to it would be bad design anyway (e.g. If you try to access a destroyed object in c++ the program would most likely crash with an access violation).

If you were to remove all the references to the object the problem of reusing it when its data is no longer valid wouldn't exist.

Alternatively you could set a instance variable like '$noMoreValid' to true. That way you could check with a simple if statement if the object is still valid.

NetNessie 04-03-2007 07:15 AM

Re: Quick PHP5 question - Object self-destruct
 
I agree with Black Yeti, forcing an object to commit suicide is bad practice. Can you give us some idea why you need it to terminate itself so we can suggest alternatives? :D

Foxy 04-03-2007 08:20 AM

Re: Quick PHP5 question - Object self-destruct
 
Ya, comments on the bug report for unset($this) not working said the same thing.

Quote:

AFAIK you cannot explicitly destroy objects in php. They are automatically destroyed as soon as there are no more references pointing to it. Destroying objects while there are references pointing to it would be bad design anyway (e.g. If you try to access a destroyed object in c++ the program would most likely crash with an access violation).

If you were to remove all the references to the object the problem of reusing it when its data is no longer valid wouldn't exist.
What I'm writing is an interface for other people. When they've manipulated an object, it becomes unsafe to reuse. (this is a limitation of what it deals with, not with my code).

Thus, if some berk were to reuse one of these objects in his code against my instructions, it would behave unpredictably and cause a major debug headache. If they destroy themselves, berk would get a fat PHP error, which is very easy to see the cause of.


All times are GMT -6. The time now is 11:24 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.

Website is 1987-2014 Apogee Software, Ltd.
Ideas and messages posted here become property of Apogee Software Ltd.