note 78737 added to language.oop5.decon

From: Date: Thu, 25 Oct 2007 09:45:36 +0000
Subject: note 78737 added to language.oop5.decon
Groups: php.notes 
Request: Send a blank email to php-notes+get-131720@lists.php.net to get a copy of this message
I recently found, while implementing a database backed session class, that PHP has an apparently less than desirably structured destruction order. Basically, my session class which would have saved when destructed, was being destructed after one of the classes it depends on. Apparently we cannot, therefore depend on PHP to use reverse initialisation order. My solution was to use register_shutdown_function, which is called before any objects are killed on script end. Quick example (if you're going to use it, I recommend tidying up the code somewhat) : <?php class Session function __construct() { //Initialise the session here... //Register the shutdown function register_shutdown_function(array($this,"save")); } function save() { //Save it here } function __destruct() { //Persisting the session here will not work. } ?> ---- Server IP: 194.145.210.4 Probable Submitter: 217.34.238.21 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php Edit -- https://master.php.net/note/edit/78737 Del: integrated -- https://master.php.net/note/delete/78737/integrated Del: useless -- https://master.php.net/note/delete/78737/useless Del: bad code -- https://master.php.net/note/delete/78737/bad+code Del: spam -- https://master.php.net/note/delete/78737/spam Del: non-english -- https://master.php.net/note/delete/78737/non-english Del: in docs -- https://master.php.net/note/delete/78737/in+docs Del: other reasons-- https://master.php.net/note/delete/78737 Reject -- https://master.php.net/note/reject/78737 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131720) next »