Tuesday, October 4, 2011

Show all available PHP variables - get_defined_vars

If you want to find out what variables are defined in the current scope during PHP execution, you can use the get_defined_vars() function. This is particularly useful when working in Drupal's .tpl.php files where you want to see what variables are getting passed into the template file.

var_dump(get_defined_vars());

I somehow have a mental block with this function name and usually end up searching for it with terms like "show available variables in PHP", which isn't very helpful, except from now on, when I search for that on Google, I'll get this post to remind me ;-)

See also:
get_defined_vars()
get_defined_constants()
get_defined_functions()

This should also come up under php variables in scope. Thanks, Google!

Reference:
http://robshouse.net/page/show-all-available-php-variables-get-defined-vars

No comments: