7.11.3. Discussion
It's rare to have an object and be unable to examine
the actual code to see how it's described. Still,
these functions can be useful for projects you want to apply to a
whole range of different classes, such as creating automated class
documentation, generic object debuggers, and state savers, like
serialize( ).
Both get_class_methods( ) and
get_class_vars( ) return an array of values. In
get_class_methods( ), the keys are numbers, and
the values are the method names. For get_class_vars(
), both variable names and default values (assigned using
var) are returned, with the variable name as the
key and the default value, if any, as the value.
As a result, you can use it to check the status of an object as it
currently exists in a program:
$clunker = new car;
$clunker_vars = get_object_vars($clunker); // we pass the object, not the class
Since you want information about a specific object, you pass the
object and not its class name. But, get_object_vars(
) returns information in the same format as
get_class_vars( ).
This makes it easy to write quick scripts to see if
you're adding new class variables:
$new_vars = array_diff(array_keys(get_object_vars($clunker)),
array_keys(get_class_vars('car')));