Introspection in PHP - Get_Class_Vars() and Get_Method_Vars()
In PHP you can perform introspection on objects and classes, which allows you to discover information about the class at runtime. This is useful for things like writing generic debuggers and state savers (like serialize()).
One of the most useful functions is get_class_vars(), which returns an associative array of the default properties for a given class. It accepts a single argument, which is the name of the class to inspect.
This function is similar to get_method_vars(), which returns the names of all methods defined for a particular class. However, get_class_vars() only reports the names of variables that are public, whereas get_method_vars() also reports the default values for those variables.
Both get_class_vars() and get_method_vars() return an associative array of keys and values, with the key being the variable name and the value being its default value. In addition, both of these functions allow you to pass in a parameter, which can be either the object itself or the class name.
Unlike get_class_vars(), get_method_vars() can be called with a NULL value for the object, but as of PHP 4.2.0 NULL will no longer raise an error when used in this manner. However, you should note that getting a NULL value from the class object will not expose any private or protected properties. This is because of the way that static binding in PHP works, and how __CLASS__ works with inherited classes. This is an improvement over previous versions of PHP, where the private and protected properties were prefixed with nul bytes.