A reflect() Function For Quick Reflection in PHP

The Reflection API is the perfect way to reverse engineer and inspect php objects and functions. I have written a function to quickly pass params to the Reflection API and get things done.

Here’s the source codes:

 
<?php
 
function reflect($data,$return = false) {
    $string = "\n \nReflecting: {$data} \n";
    $string .= "\n====================\n";
    if(is_object($data)) {
        $string .= Reflection::export( new ReflectionClass($data), true );
        $string .= "\n====================\n";
    } else {
        if(function_exists($data)) {
            $string .= Reflection::export( new ReflectionFunction($data), true );
            $string .= "\n====================\n";
        }
    }
 
    if($return) {
        return $string;
    } else {
        echo $string;
    }
 
}
?>
This entry was posted in Blog Post and tagged . Bookmark the permalink.

One Response to A reflect() Function For Quick Reflection in PHP

  1. Pingback: A reflect() Function For Quick Reflection in PHP « maSnun.com | Coder Online

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">