From:             sampw at hotmail dot com
Operating system: Win XP SP2
PHP version:      5CVS-2004-08-15 (dev)
PHP Bug Type:     Class/Object related
Bug description:  Destructor is called to late, unset do not work

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 bug report at http://bugs.php.net/?id=29685&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=29685&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=29685&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=29685&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=29685&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=29685&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=29685&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=29685&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=29685&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=29685&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=29685&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=29685&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=29685&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29685&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=29685&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=29685&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=29685&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29685&r=float

Reply via email to