I am a Permanent Member (or Community Ambassador) of the Drupal Association.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(). This should also come up under php variables in scope. Thanks, Google!
Comments
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.
Thanks
This was exactly what I was looking for. I searched for "variables available at time of execution php" and this page was the first to come up.
Funny that I was actually looking for this because I am debugging a drupal site which had nothing to do with my search string.
Great help, didn't know this function yet :)
Thanx for this article. It really helped me finding out about the weird erros on my website. The link below is the wbesite. It's a dutch site about cheaper international calling en worldtime. See Wereldklok (worldclock).
ahah exectly what I needed;
ahah exectly what I needed; and in this case, for block.tpl.php ;p
php see all variables
This post comes up second in Google for php see all variables. Maybe this will help someone else find it. Thanks!
can't remember how long I have been looking for this function
can't remember how long I have been looking for this function.
I have been looking for this function for so long in order to use it with my tpl.php files, only to find that it was right under my nose on the phptemplate page.
Looking for it in Google brought me straight here.
Cheers
You get used to having all this stuff at your fingertips when you are working with a framework - when you aren't and you're coding from scratch, you really miss all the useful debug stuff.
Thanks for the tip.
Great idea!
Awesome idea, exactly how I got to this page.
I searched for it before this page was online and it took me 15 minutes to find it, so thank you!
My search term was:
php get all variables in scope
Hahahahha
My search term: php show current variables
Me too.
I always forget about get_defined_vars().
I use this to dump a formatted array to the browser:
printf('%s', print_r(get_defined_vars(), 1));
I use: ob_end_clean(); echo
I use:
ob_end_clean();
echo ''.htmlentities(print_r(get_defined_vars(), 1)).'';
die;
That way you don't get rendered HTML, and discard the current output.
Post new comment