+ 2

What is the rational behind the variable variable ability in php?

22nd Dec 2017, 7:42 PM
EMMANUEL NUOTAH TUONUO DERY
EMMANUEL NUOTAH TUONUO DERY - avatar
3 odpowiedzi
+ 4
I think it's pretty cool actually $a = "s"; $c = "a"; echo $c;
22nd Dec 2017, 8:19 PM
David Akhihiero
David Akhihiero - avatar
22nd Dec 2017, 7:52 PM
James16
James16 - avatar
+ 1
I can only guess. As with a lot of PHP's features it's probably "because other languages had it" when PHP came out. PHP is a kitchen sink full of bad features. I distinctly remember that variable variables were very common in TI-Basic, because a lot of data you worked with was strings, and managing arrays was a bit of a hassle. So building strings like "v1", "v2", "v3", and using variable variables to use them as variable names was not only easiest, but also shortest (which is important when programming on a calculator!) I think bash and perl have it too. As for PHP? It probably should have never been a thing. PHP wanted to imitate C, so maybe they thought PHP needed pointers, but pointers make no sense in PHP so they made variable variables instead. Maybe there even was a use-case way back when (PHP gained a lot of features over the years), but there most definitely isn't one now. Bottom line: Never use variable variables!
22nd Dec 2017, 9:56 PM
Schindlabua
Schindlabua - avatar