Where are all my PHP variables hiding?Posted October 28th, 2007 by Chris
Sometimes it's difficult to remember what variables you have available to you at any given time, especially if your script is split into functions, or in my case you're working with Drupal, where there's a whole slew of variables available at your disposal, if only you know what they were called. Lucky for curious folks like us, there's a couple native PHP functions that will clear things up:
//Prints out the contents of whatever variable you pass to it.
The killer combo
This will print out all the variables currently available to you, and then kill the script so you can just look at the output. Var_dump() prints out the variables in text format, so you'll find it a bit easier to check out your browser's "view source" to see the spacing. Sometimes, when I'm tracking a deep variable I'll copy the code and paste it into Dreamweaver, where I can measure the indents.
I'm also hoping this entry will help me keep track of those function names, because it's mentally strenuous to articulate to Google exactly what the function I'm looking for does. "Output all PHP variables .... in some format I can read ... please?"