ID: 29685 Updated by: [EMAIL PROTECTED] Reported By: sampw at hotmail dot com Status: Bogus Bug Type: Class/Object related -Operating System: Win XP SP2 +Operating System: * -PHP Version: 5CVS-2004-08-15 (dev) +PHP Version: 5.* New Comment:
Well i must admit i haven't tried with sessions yet. They are closed during R-shutdown pahse and at least theoretically dtor's should be called kust before R-shutdown begins. If that is not the case we must either fix ext/session or something else. Until that is clear you need an explicitly shutdown function for your singleton (one that unsets the static member). Previous Comments: ------------------------------------------------------------------------ [2004-08-15 15:56:51] sampw at hotmail dot com The dtor is called during shutdown. Yes, but to late! In other bug reports, you called it a feature to use unset at the end of a script inorder to get a reliable working destructor. Because otherwise functions like $this->sessionWriteClose();, which rely on other objects doesn't work reliable. That works fine, if you doesn't use a classical singleton implementation. Because here unset does not work (because there exist a private static reference inside the object!), which means that the destructor doesn't work correctly ($this->sessionWriteClose() works not!). If you said that, that isn't a bug, I have to suggest that a classical singleton implementation with a reliable working destructor is not possible in php?? Sounds poor ... ------------------------------------------------------------------------ [2004-08-15 15:10:39] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php The dtor is called during shutdown. I don\'t see the slightest problem here. ------------------------------------------------------------------------ [2004-08-15 01:28:06] sampw at hotmail dot com Description: ------------ Destructor is not called to late. If you use a singleton pattern unset does not work, because there exist a private static reference for the object. Why is the destructor called so unreliable? Is such a singleton pattern not possible in PHP? Or must the static $instance be public, inorder to unset it manually? (Not a nice solution?!) Reproduce code: --------------- class Session { //Db Session (Singleton) static private $instance = false; private function __construct() { } public function __destruct() { $this->sessionWriteClose(); // e.G. store session data } static function instance() { if(!Session::$instance) Session::$instance = new Session(); return Session::$instance; } } $OBJ_SESSION = Session::instance(); unset($OBJ_SESSION); // Does not work, because of the static private $instance ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29685&edit=1