Hello Internals,

I'm thinking about a new function returning an array of classes and their
individual number of instances. It would look pretty much like the result of
get_declared_classes().


An Example:

print_r (get_instantiated_classes());
// Array ()

$foo = new StdClass;

print_r (get_instantiated_classes());
// Array ( [StdClass] => 1 )

$bar = new StdClass;

print_r (get_instantiated_classes());
// Array ( [StdClass] => 2 )

... and so on

 
Such a function could be helpful when refactoring and/or optimizing an
application. Just think of implementing the flyweight pattern in parts of an
application, where it is applicable. You could check against precise
numbers, for example when you're expecting the number of instances to
decrease by a certain number. Besides microtime() and get_memory_usage(), it
could be another useful indicator.

Since I'm neither familiar with C nor the Zend Engine, I cannot implement
the feature and do not know, if it is even possible.

But first of all, I'm asking you for your opinions.


Frank


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to