I am currently using this method:
class Foo { private static $num_instances = 0; function __construct() { self::$num_instances++; } }
which seems to work, but I wonder if there is a built-in way ....
I would be surprised if he is. In my opinion, it will be overhead if it always counts the number of created copies.
You can use xdebug using execution trace .
You can always check $GLOBALS and count the number of class instances.
$GLOBALS
That would not be the case, and I would rather do it with a static property.