SimpleReflector for PHP
This is an easy-to-use reflection class for exposing an object's identity so problems can be debugged quickly.
It does correct null/true/false/empty string detection. A string just gets output directly, whereas objects will have their class interfaces exposed. Everything dumped to screen is correctly escaped for HTML output so the rest of the page doesn't break.
The following information is displayed for objects:
- Class file/line location (especially useful when the same name class is defined multiple times in the filesystem)
- Methods in the class, including parameter names.
- Contents of the object (simple print_r that is HTML escaped)
Download
Download SimpleReflector 1.0, view the source or fork it on github.
This software is released under the FreeBSD License (revised). (You can use it for free on your personal and commercial projects.)
Installation
Simply include the class and make calls to it. If you are using the PHP Autoloader then you won't even have to include it.
Example Usage
<?php
// echo info to screen (most common case)
SimpleReflector::jam($object);
// returns info as a string
$str = SimpleReflector::jam($object, true);
// echo info to screen with a custom title instead of "SimpleReflector"
SimpleReflector::jam($object, false, 'crazy object');
Suggestion
For quicker use, consider adding a short function to your applications:<?php
function jam() {
$args = func_get_args();
call_user_func_array(array('SimpleReflector', 'jam'), $args);
}
Then instead of typing `SimpleReflector::jam(...)` you can just type `jam(...)`.