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?
PHP 5 Bug or not?
Moderator: General Moderators
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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.. 
- andre_c
- Forum Contributor
- Posts: 412
- Joined: Sun Feb 29, 2004 6:49 pm
- Location: Salt Lake City, Utah
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?
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?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
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..
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..