I would like to make PHP print out debugging information, including the full path to the .php file, to standard error whenever it loads a class: e.g.
Loaded MyClass from /path/to/my/class/MyClass.php
is there any way to do this without knowing in advance where the source files are?
[edited to clarify that I really care about the full path to the .php file, and that I don’t know in advance where the source files are]
Since PHP does not have static constructors, you cannot automagically do something when a class is loaded. Your best bet is probably to print the message after the class definition (or use
__autoloadas Josh instructed, but that might require some reworking on your end).EDIT Sorry to say, but PHP provides absolutely no hook to when a class is loaded or first instantiated, even in the dirtiest corners of its weird extensions. You will not be able to get away without either editing the classes’ source files (and use my solution) or organize them in a conventional hierarchy to put them in (and use Josh’s solution).
There is feature request #48546 that asks for a way to set a callback to when a file will be included but it’s not going anywhere. Otherwise, people seem content with
__autoload.At best, you may call
get_declared_classesat any time and see what’s already been loaded.