Re: how to count objects instances
| From: | Robert Cummings | Date: | Tue, 24 Aug 2004 01:04:35 +0000 |
| Subject: | Re: how to count objects instances | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-194546@lists.php.net to get a copy of this message | ||
On Mon, 2004-08-23 at 20:33, Curt Zirzow wrote:
> * Thus wrote Robert Cummings:
> > On Mon, 2004-08-23 at 20:54, John Holmes wrote:
> > > tyler@carbon.homelinux.com wrote:
> > >
> > > You could write a wrapper class for Test that kept count of the
> > > instances and returned a new object upon request...
> >
> > In PHP5:
> >
> > <?php
> >
> > class Foo
> > {
> > static $instances = 0;
> >
> > function __construct()
> > {
> > Foo::$instances++;
> > }
> >
> > function __destruct()
> > {
> > Foo::$instances--;
> > }
>
> And:
> function __clone()
> {
> Foo::$instances++;
> }
Perfect. I hadn't thought of that :)
Cheers,
Rob.
--
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com
|
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'