note 66383 added to function.session-set-save-handler
| From: | djmaze at cpgnukecms | Date: | Sat, 20 May 2006 17:51:24 +0000 |
| Subject: | note 66383 added to function.session-set-save-handler | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-111739@lists.php.net to get a copy of this message | ||
Since register_shutdown_function() and __destruct() will not work on object based sessions,
ESPECIALY when they are database based thru a class, then it seems you're screwed.
Issue:
register_shutdown_function('shutdown_function');
new sql();
new session();
on destruct:
sql __destruct()
session __destruct() // can't call sql since already destroyed
shutdown_function() // can't call instances since already destroyed
A trick is to use an "first class instance"
<?php
class my_proper_destructor
{
protected $destroyers = array();
function add($class_instance)
{
if (is_class($class_instance))
$destroyers[] = $class_instance;
}
function __destruct()
{
foreach($destroyers as $des)
$des->on_destroy();
}
}
$destruct = new my_proper_destructor();
// All your code starts here like:
class session
{
function __construct()
{
global $destruct;
$destruct->add($this);
}
}
?>
Since my_proper_destructor is created first it also gets destroyed as the first. That way you can
still call important class instances that need to do something on destruct.
----
Server IP: 194.109.193.119
Probable Submitter: 82.197.202.154
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.session-set-save-handler.php
Edit -- http://master.php.net/note/edit/66383
Del: integrated -- http://master.php.net/note/delete/66383/integrated
Del: useless -- http://master.php.net/note/delete/66383/useless
Del: bad code -- http://master.php.net/note/delete/66383/bad+code
Del: spam -- http://master.php.net/note/delete/66383/spam
Del: non-english -- http://master.php.net/note/delete/66383/non-english
Del: in docs -- http://master.php.net/note/delete/66383/in+docs
Del: other reasons-- http://master.php.net/note/delete/66383
Reject -- http://master.php.net/note/reject/66383
Search -- http://master.php.net/manage/user-notes.php