Jak Posted November 8, 2006 Share Posted November 8, 2006 Hi, I’m using a custom session handling class in my application, however I’m having trouble with the session write method. I’m using __destruct methods in a couple of classes to modify values in the SESSION variable, but some (not all) of the changes I make are not being saved.At first I thought it was because PHP was running the session handlers write function before the __destruct methods in my classes, however I have since discovered that its not running the write method at all (sometimes).I added a line into each of the relevant functions to log what was happening to a file, this is what I got:[code]** NEW REQUEST **SESSION CONSTRUCTORSESSION READFORM DESTRUCTOR** NEW REQUEST **SESSION CONSTRUCTORSESSION READVALIDATION DESTRUCTORSESSION WRITE** NEW REQUEST **SESSION CONSTRUCTORSESSION READFORM DESTRUCTOR[/code]So on the first request (the initial page load) the session is being created, a form is created on the page, and the forms destructor is run.The second request is the post to the server from the form. The session is fine, the validation classes destructor is run (which writes validation data to the session variable) and then the session write function is run, ALL GOOD.On this occasion the form failed validation so the third request is the redirect back to the original form. The session is fine, the form destructor is fine (which removes the validation data that the validation class added, as this has been used earlier in the form class) however for some reason the session write method has NOT been run.Does anyone have any idea why this would happen? I’m completely confused, I assumed the write function would run at the end of every request, and it certainly should if the session data has changed.Thanks in advance, Jack Quote Link to comment https://forums.phpfreaks.com/topic/26588-why-wont-the-session-write-function-run/ Share on other sites More sharing options...
Jak Posted November 8, 2006 Author Share Posted November 8, 2006 Hey,Dont worry, ive fixed it, not that i have any idea how. I rewrote the session handling class to work in a different way and the problem seems to have resolved itself. Quote Link to comment https://forums.phpfreaks.com/topic/26588-why-wont-the-session-write-function-run/#findComment-121695 Share on other sites More sharing options...
sennetta Posted February 23, 2011 Share Posted February 23, 2011 This thread is four years old, but it comes up on Google. Here is something that might be related for future people who come across this: http://bugs.php.net/29032 Basically $_SESSION is destroyed/unwritable/unpredictable/crap when called in destructors (which could be after execution has finished). Also, the bug report is 7 years old, so may not be the case at all. All I can say is that for me, calling $object->__destruct(), where $object is a singleton, works fine, but is not a very neat way of doing it. Quote Link to comment https://forums.phpfreaks.com/topic/26588-why-wont-the-session-write-function-run/#findComment-1178756 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.