note 94945 deleted from language.oop5.decon by levim

From: Date: Tue, 18 Mar 2014 02:06:26 +0000
Subject: note 94945 deleted from language.oop5.decon by levim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-198911@lists.php.net to get a copy of this message
Note Submitter: jon at fatcatsoftware dot net ---- I'm not sure why this was happening, but I had an instance were the __destruct was being called BEFORE my __construct in a certain class. I'm using a Factory Class where I would call this statement to grab the class: <?php public static function &getBookingSession() { static $instance =null; if (is_null($instance)) { //requiring the class file require_once 'bookingSession.php'; //request the instance $instance = new bookingSession(); } return $instance; } ?> The __destruct was actually being called each time I grabbed this class with <?php $session =& Factory::getBookingSession(); ?> Only after the destruct ran once or twice the construct would run. Obviously causing some major problems. MY SOLUTION: was to call the register shutdown function in my fake session construct, like so: <?php class bookingSession { function __construct(){ $session =& Factory::getSession(); $this->setProperties( unserialize(base64_decode( $session->get('bookingSession') )) ); $this->setProperties(JRequest::get('post')); register_shutdown_function(array($this,"destruct")); } */ function destruct() { $session =& JFactory::getSession(); $session->set( 'bookingSession', base64_encode (serialize ($this)) ); } } ?>

« previous php.notes (#198911) next »