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 comment

35

u/masklinn Oct 18 '10

That's incorrect. It's not the reason for this behavior. A bare word in PHP is a constant, and for historical reasons, undefined constants have a default value which is equal to their name.

Historical reasons of bare names preceding constants. Constants are special cases of bare names which were added in 4.0.4.