Sometimes I have trouble with web applications where I need to find where a class is defined. Depending on the code base you’re working on it can be easy (in the case of PSR0 based projects) to determine this, but in other cases definition of the classes can be done anywhere.
include 'path/to/some/classes.php'; include 'some/more/classes.php'; $object = new SlushyMachine();
In this case maybe the class you’re looking for is defined in one of those two files? Maybe it isn’t … and although you can work with $object it’s difficult to find where SlushyMachine() is defined. You can search for it, but if that fails there is another way.
PHP has a set of reflection tools and we can drop a one-liner into a script to find out where the object is defined:
echo (new ReflectionClass($object))->getFileName());
For more information on PHP’s reflection ablilities, check out the PHP Reflection section of the PHP manual.