On Mon, 2004-08-23 at 20:54, John Holmes wrote:
> [EMAIL PROTECTED] wrote:
> > hi,
> > What is best method(if it's possible) to count how many times an object is
> > instanced in one time script call?
> > I means that if i have a class named "Test", i what to know how many times she's
> > called, how many copies exists etc. The idea is for monitoring in the way to
> > optimizing the code.
> >
> > The method get_declared_classes() only shows only the classes included/required.
>
> There's no predefined variable or method for determining this, that I'm
> aware of, short of counting how many "new Test" lines you have.
>
> 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--;
}
static function getNumInstances()
{
return Foo::$instances;
}
}
$foo = new Foo();
$fee = new Foo();
echo 'Count: '.Foo::getNumInstances()."\n";
unset( $foo );
echo 'Count: '.Foo::getNumInstances()."\n";
--
.------------------------------------------------------------.
| 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. |
`------------------------------------------------------------'
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php