Page 1 of 1

PHP 5 Bug or not?

Posted: Tue Aug 24, 2004 6:24 pm
by andre_c
I found out that when a destructor sets values in a $_SESSION array, the values are not saved to the session.
I thought it was a bug and went to report it, but someone else had reported it already and the php devs told him that it wasn't a bug and that it was the right behavior.

http://bugs.php.net/bug.php?id=27903

Can anyone tell me why this is considered to be the correct behavior of a destructor?

Posted: Tue Aug 24, 2004 6:36 pm
by feyd
in the application world, destructors are not supposed to set any values, anywhere. They are just around to destroy the object they control. Anything else, is done by a/the garbage collection routine calling the destructor. Destructors are supposed to be independant of most things.. it is odd though that they've chosen to destroy the core variables first.. destruction is done in reverse of creation.. :?

Posted: Tue Aug 24, 2004 6:43 pm
by andre_c
If destructors are not supposed to set values, then what is the purpose of a destructor method?

It just seemed great to me that maybe i could save an object to the session using the destructor and then recreate from the session using it's constructor with out having code outside of the object.

Can you show me a sample of code that would make sense to put in a constructor method in PHP?
or what is the destructor method in php good for?

Posted: Tue Aug 24, 2004 6:57 pm
by feyd
since php is entirely memory managed, destructors have little to no value.. because we can't control outside memory (maybe the Shared Memory stuff), there's often little to really destroy.. at least at script end..

used throughout a page though, they can be more useful because you can free mysql results, if that's what the class does.. but because of the oddity of their choice in order of destruction, you'd have to make sure you free ones that persist beyond the script's lifetime before the script actually ends.. which kinda sucks..

Posted: Tue Aug 24, 2004 7:02 pm
by andre_c
I hope they fix the order to something that makes more sense. Which doesn't seem like they will, since they dismissed the bug report.

Thanks for your help.

Posted: Tue Aug 24, 2004 7:06 pm
by feyd
yeah.. although I'd have to run through the code to make sure it's actually destroying in the reverse of what it should.. maybe in a few months when I get some extra time.. :lol: