Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use a variable variable in PHP?

I've been developing in PHP for a while now, and I still have not had a task where I've had to use variable variables. Can anyone give me examples where using them is a good idea ? Or were they included in the language just for fun ?

like image 383
sjobe Avatar asked Jun 16 '09 19:06

sjobe


2 Answers

I generally find them in places where the code smells bad. Maybe references a static configuration variable etc... But why wouldn't the usual associative array have been a better solution. Seems like a security hole waiting to happen.

I suppose you might be able to use them in templates effectively.

like image 135
cgp Avatar answered Oct 08 '22 23:10

cgp


Never use them; an "array" is always a better solution.

like image 32
jrockway Avatar answered Oct 09 '22 00:10

jrockway