NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP 5 singleton/destructor question

David Mintz dmintz at davidmintz.org
Fri Apr 1 10:28:39 EST 2005


>From dmintz at davidmintz.org Fri Apr  1 10:20:24 2005
Date: Fri, 1 Apr 2005 10:19:36 -0500 (EST)
From: David Mintz <dmintz at davidmintz.org>
To: Daniel J Cain Jr. <dan at cain.sh>
Subject: Re: [nycphp-talk] PHP 5 singleton/destructor question

On Fri, 1 Apr 2005, Daniel J Cain Jr. wrote:

> PHP tracks the number of references to a variable, when there are no
> more references it can safely be destroyed by the Zend engine.  So the
> count should be at 2. One for the instance you grab in the main script
> and another for the static reference inside the class definition.  You
> need to run two unsets(one inside the class, and one outside the class)
> to make that variables reference count == 0.

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.

Thanks,

---
David Mintz
http://davidmintz.org/



More information about the talk mailing list