Forum Archive

Go Back   3D Realms Forums > General Topics > Programming Forum
Blogs FAQ Members List Social Groups Calendar Mark Forums Read

Notices

 
 
Thread Tools
Old 03-07-2007, 06:19 AM   #1
Foxy
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).
Foxy is offline  
Old 03-07-2007, 07:00 AM   #2
Phait

Phait's Avatar
Re: Quick PHP5 question - Object self-destruct
Try http://www.faqts.com/knowledge_base/index.phtml/fid/51
__________________
Music: http://www.oquilluksound.com Album: http://machinefaultred.blogspot.com Album Calendar Youtube: http://www.youtube.com/oquilluksound

"but I promise you this, I'll always look out for you, that's what I do" -Coldplay
Phait is offline  
Old 03-07-2007, 12:40 PM   #3
Foxy
Re: Quick PHP5 question - Object self-destruct
Nothing there.
Foxy is offline  
Old 03-07-2007, 12:45 PM   #4
Phait

Phait's Avatar
Re: Quick PHP5 question - Object self-destruct
Try http://www.phpbuilder.net forums
__________________
Music: http://www.oquilluksound.com Album: http://machinefaultred.blogspot.com Album Calendar Youtube: http://www.youtube.com/oquilluksound

"but I promise you this, I'll always look out for you, that's what I do" -Coldplay
Phait is offline  
Old 03-08-2007, 08:18 PM   #5
AlienAssKicker

AlienAssKicker's Avatar
Re: Quick PHP5 question - Object self-destruct
Can't you explicitly call the __destruct() function?
AlienAssKicker is offline  
Old 03-09-2007, 05:35 AM   #6
Foxy
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.
Foxy is offline  
Old 04-02-2007, 07:02 PM   #7
Black Yeti
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.
Black Yeti is offline  
Old 04-03-2007, 07:15 AM   #8
NetNessie

NetNessie's Avatar
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?
__________________
Ink Grass LazyMoon Photography
"Say something wise, and your name will be remembered forever." - Anonymous
NetNessie is offline  
Old 04-03-2007, 08:20 AM   #9
Foxy
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.
Foxy is offline  
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:46 AM.

Page generated in 0.13754296 seconds (100.00% PHP - 0% MySQL) with 16 queries

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.