NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP 5 singleton/destructor question

Dan Cech dcech at phpwerx.net
Fri Apr 1 12:51:50 EST 2005


David Mintz wrote:
> I think I get what you're saying... or maybe not. No instantiation, no
> destructor runs -- I understand "static". Yet I believe an object of
> class MyDatabase is instantiated in the example I posted earlier, and it
> has a __destruct()  method, so its __destruct() should run when PHP
> decides the reference count is zero. Does the reference count NOT reach
> zero when the script terminates, no matter what? If you haven't explicitly
> unset() or set to NULL, php cleans up the garbage for you before the
> process ends, no?
> 
> Maybe the register_shutdown_function() hack isn't such a bad solution.

My guess would be that the destructor *is* called, just that unless you 
manually run it, via register_shutdown_function or whatever, it's called 
by the garbage collector *after* the page is sent to the browser...so 
you would't see the output.

I could be totally wrong though...

Dan



More information about the talk mailing list