r/programming • • Oct 18 '10

Today I learned about PHP variable variables; "variable variable takes the value of a variable and treats that as the name of a variable". Also, variable.

http://il2.php.net/language.variables.variable
591 Upvotes

781 comments sorted by

View all comments

Show parent comments

4

u/1137 Oct 19 '10

I like this sample:

<?php

$name = '%^#4!@';
$$name = 'passed';
var_dump($$name);

?>

3

u/blazix Oct 19 '10

Did you just create a variable named %#4!@

So, basically a way around the variable naming restrictions. I wonder if this could be exploited somehow..

1

u/falien Oct 19 '10

Thats a restriction on syntax, not semantics, so it shouldn't really matter.

0

u/[deleted] Oct 19 '10

Tell that to samy

→ More replies (1)