note 94945 added to language.oop5.decon

From: Date: Thu, 03 Dec 2009 21:33:47 +0000
Subject: note 94945 added to language.oop5.decon
Groups: php.notes 
Request: Send a blank email to php-notes+get-163553@lists.php.net to get a copy of this message
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)) ); } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 98.247.229.102 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.decon.php Edit -- https://master.php.net/note/edit/94945 Del: integrated -- https://master.php.net/note/delete/94945/integrated Del: useless -- https://master.php.net/note/delete/94945/useless Del: bad code -- https://master.php.net/note/delete/94945/bad+code Del: spam -- https://master.php.net/note/delete/94945/spam Del: non-english -- https://master.php.net/note/delete/94945/non-english Del: in docs -- https://master.php.net/note/delete/94945/in+docs Del: other reasons-- https://master.php.net/note/delete/94945 Reject -- https://master.php.net/note/reject/94945 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163553) next »