Tag Archives: print_r

PHP Get Object Vars / PHP Get Object Methods

Have you written an application and wanted to see if the result set from your database request returned the correct results?

Have you worked with someone else’s code and had to use an object but wasn’t sure what kind of variables and methods that object contains?

Well now you can check all of that (class properties/variables, class methods/functions and their values).

PHP’s function print_r() will allow you to view properties and values of the following: array, object, variables.

The function var_dump() allows you to do exactly the same thing, except; this function will output results in the browser’s console, tell you the variable’s type and its values.

The previous two functions allow you to view only properties and their values, but what if you want to know which functions/methods the class has available at its disposal? In that case, use get_class_methods() which will output exactly what you want.

To wrap this up, use print_r(), var_dump(), and get_class_methods() for your testing and exploration needs.