|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2012-05-05 18:36 UTC] dev at pp3345 dot de
 Description: ------------ I'd like to have a function that returns all instances of a given class with information about where it was instantiated and referenced. This could really help in debugging. A possible implementation could be get_instances(string $class_name); or ReflectionClass::getInstances(string $class_name); PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 15:00:01 2025 UTC | 
This information is not easily available from the engine and tracking it would be quite expensive. If you need it, you can do it using something like this: (untested) $tracked_objects = array(); // Global class TrackedClass { public function __construct() { $GLOBAL['tracked_objects'][spl_object_hash($this)] = array( 'class' => get_class($this), 'stack' => debug_backtrace() ); } public function __destruct() { unset($GLOBAL['tracked_objects'][spl_object_hash($this)]); } } Any class you want to track can than be extended from such a class (or use 5.4 and traits) andyou can inspect $tracked_objects.