PHP 5 Bug or not?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

PHP 5 Bug or not?

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.. :?
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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:
Post Reply