I saw at least another thread discussing this, but none under "code matters" (and none containing a good solution IMO), and I wanted to make sure this is read by the right people so I decided to submit a bug report.
Call to a member function Execute() on a non-object in ...includes\functions\sessions.php on line 61
According to http://www.php.net/session_set_save_handler, session "Write and Close handlers are called after destructing objects since PHP 5.0.5". Why this was not a problem in ZC and other scripts between PHP 5.0.5 and 5.2 I don't know, and I can't say I'm much wiser after skimming through the PHP changelog either because some of the bugs that were fixed in PHP5.2 (that could be related to this issue) were not well described.
Anyway, the problem is that ZC won't work properly with custom session handler (db) in PHP5.2, and the reason seems to be (assuming I've got the facts right) that objects are destroyed before the session is written, as stated in the PHP manual and quoted above. In other words, the $db object, which is needed by the custom db session handler, won't be available to the session save and close handlers.
I saw another workaround for PHP5.2 mentioned somewhere in these forums that instantiated a new $db object in the custom session write handler, but that's not necessary if the session is written and closed before objects are destructed, and that can be accomplished by calling session_write_close() at script shutdown, ie.
Code:
register_shutdown_function('session_write_close');
The above line should be called whenever session_set_save_handler() is called (and the session write handler makes use of objects), so I'll suggest a wrapper function.
Code:
function zc_session_set_save_handler ($open, $close, $read, $write, $destroy, $gc)
{
if (session_set_save_handler($open, $close, $read, $write, $destroy, $gc) === false)
{
return false;
}
# write and close session at the end of script, and before objects are destroyed (required for PHP5.2)
register_shutdown_function('session_write_close');
return true;
}
and replace calls to session_set_save_handler() with zc_session_set_save_handler().
Bookmarks