NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP 5 singleton/destructor question

Daniel J Cain Jr. dan at cain.sh
Thu Mar 31 19:29:07 EST 2005


I would think that your static $db inside the MyDatabase class is why 
your not having your destructor called prior to the script ending.

When you do:

$outsideDB = MyDatabase::getInstance();

$outsideDB should be a reference to the private static $db inside 
MyDatabase.  So you can unset that in the script, but it only removes 
the reference to the hidden $db.  And being that internal $db still 
references the object you created __destruct() won't be called.

It will be called when the script terminates, but I believe the output 
buffers are closed by this point--so echo in the __destruct() won't be seen.

You could try another method that unsets the $db inside the class to 
prove or disprove my theory.



David Mintz wrote:
> OK, here is the ugliest workaround you've seen all day. A pint of beer for
> anyone who can explain why I am having to do this. I added to my
> constructor:
> 
> register_shutdown_function(array($this, '__destruct'));
> 
> and it works, so to speak.
> 
> ---
> David Mintz
> http://davidmintz.org/
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org





More information about the talk mailing list