tags:

views:

77

answers:

3

I'm currently using this method:

class Foo {
    private static $num_instances = 0;

    function __construct() {
        self::$num_instances++;
    }
}

which seems to work, but I'm wondering if there's a built in way....

A: 

I would be surprised if there is one..
In my opinion it would be an overhead, if it is always counting the amount of created instances.

Prine
A: 

You could use xdebug using the execution trace.

DaNieL
A: 

You can always check $GLOBALS and count the number of class instantiations.

It wouldn't be pretty, and I would prefer to do it with a static property.

Alix Axel