Where are all my PHP variables hiding?
Where are all my PHP variables hiding?
Posted October 28th, 2007 by ChrisSometimes 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:
get_defined_vars();
//Prints out the contents of whatever variable you pass to it.
var_dump();
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?"
Other resources you might be keen on:
- Why Do I Need Web Hosting?
- What About Designing My Own Web Site?
- What is the Difference Between Web Design and Web Development?
- Ecommerce is More Than a Shopping Cart
- The Best Web Hosting Experience I've Had
- Domain name registration is easier than throwing rocks!
- A Business Card to Be Remembered
- Is Business VOIP a Good Alternative to a Traditional Phone Line?
- Adding Stickability to your Business Web Site
- The Advantages of Internet Advertising vs. Traditional Advertising
- Say please to Google
- Create icons for free!
- Search Engine Optimization
- Drupal Evangelism - Bringing it to the schools
- MySQL plans to slap Drupal. Geek fight!




