AutoDMC's PICAYUNE INTELLIGENCE

Thoughts of small town life in Minnesota. Circulation 47.

Variable Variables

Tags: , ,

I had a job intereview today for a PHP Application Developer position.  Naturally I was nervous.  But I think I did a good job.  Except for one question:

“Define ‘Variable Variables’ as it relates to PHP.”

My brain froze.  It’s like, the words made sense… but not really.  My response was a confused look, followed by “I don’t believe I’ve heard that term in reference to PHP.”

The guy nodded, gave a half smile and moved on.

I left the interview, shook hands all around, and walked out.  I hit the button for the elevator, got in, and pressed lobby.  And then I did this:

picard-facepalm1 

For at that moment, I suddenly realized what Variable Variables were.  And worst yet… I’ve used many variable variables!

picardandrikerdoublefacnm1

Just for good Karma:

“Variable Variables” allow you to assign the name of one variable as a string in another variable, and then access the named variable.  For example:

   1:  $salutation = 'Hello, World!';
   2:  $a = 'salutation';
   3:  echo ${$a};

 

{$a} says “take the contents of the string $a and put them here as the variable name,” which turns line 3 into:

   1:  echo $salutation;

Which causes the script to print “Hello, World.”  I could explain Magic Functions, but completely blanked on Variable Variables.

I also forgot that the @ sign is used to change the error reporting level, rendering errors “suppressed,” but it’s usually a Bad Thing™ for efficiency (Excellent explanation here.  But I threw up the “It’s used for function decorators in Python!” in hopes of at least showing SOME programmer savvy (and instead mostly looking like a random dork).

I hope this post can save somebody else the humiliation of forgetting about Variable Variables… or this may just become your reaction:

facepalm

Tags: , ,

Leave a Reply

You must be logged in to post a comment.

© 2009 AutoDMC's PICAYUNE INTELLIGENCE. All Rights Reserved.

This blog is powered by Wordpress and Magatheme by Bryan Helmig.