note 66383 deleted from function.session-set-save-handler by drak

From: Date: Sun, 11 Mar 2012 02:20:26 +0000
Subject: note 66383 deleted from function.session-set-save-handler by drak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-186585@lists.php.net to get a copy of this message
Note Submitter: djmaze@cpgnuke cms ---- 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.

« previous php.notes (#186585) next »