I’ve never actually used this function, but could definitely see using it to help profile a system and/or to help identify defined but unused variables.

To obtain an array of all of the defined variables you would:

$defined = get_defined_vars();

The function returns a multi-dimensional array of all of the defined variables. This is not limited to used-defined variables, so you will end up seeing server and environment variables as well.

There are also some complementary functions that allow you to get a list of the defined functions and constants, get_defined_functions() and get_defined_constants() respectively.

Have you ever used this function or know of a good use for it? Share it in the comments below, I’d love to hear about it!