Nash's world

Tag: insanity

PHP variable variables; “variable variable takes the value of a variable and treats that as the name of a variable”. Also, variable.

by on Oct.19, 2010, under Programing

this is only the entrance of the rabbit hole.

If you understand what this expression really does, you realize that you’re gazing upon the entrance to R’lyeh.Do you think you don’t need your soul anymore? If you do, follow me into the lair of the Elder Gods. But be warned, you will die a lot inside.The first thing to understand is what 

1
$

is. 

1
$

is actually a shorthand for 

1
${}

and means “return the value of the variable whose name is contained in this”.That variable name is a string.

A bare word is a PHP string. Let that sink for a second, because we’ll come back to it later: 

1
$foo

really is the concatenation of 

1
$

the variable-indirection character (think 

1
*foo

) and 

1
foo

which is a string. 

1
foo === "foo"

in PHP, even though in raw source code you’ll probably get a warning. If those are enabled.

(continue reading…)

4 Comments :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...

IDL

Member of The Internet Defense League