Show all available PHP variables - get_defined_vars
Tagged:  •  

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() and get_defined_functions().

I have the exact same mental

I have the exact same mental block - this is the second time I’ve googled for 15 minutes to find this post. Thanks!

lol

when I searched for “drupal +getting all available variables” this page was second :p

Thanks

I knew there would be a function for this; nice simple post here proved it to me!

Thank you.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options