Array of current instances count

From: Date: Fri, 29 Mar 2013 16:50:29 +0000
Subject: Array of current instances count
Groups: php.internals 
Request: Send a blank email to internals+get-66857@lists.php.net to get a copy of this message
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

« previous php.internals (#66857) next »