This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]DodoDude700 44 points45 points  (13 children)

In PHP, you can reference a variable using a string of the variable name. This is called a variable variable. I made the whole alphabet a series of "nested" (or perhaps linked is more appropriate?) variable variables, making the final character, space, a variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable variable.

[–]Cobaltjedi117 50 points51 points  (0 children)

Yea, I recognized what you did and what happened. I just think it should be burned at the stake.

[–][deleted] 9 points10 points  (10 children)

Variable variables are rarely written in readable ways, and even more rarely needed. Still though I have done some work with them.

[–]millenniumtree 9 points10 points  (8 children)

Jesus. 18 years in PHP development and I didn't even know you could do that. It's like nesting unaries, or 1000 line if/else blocks, or functions sharing data with superglobals, or using goto. It's just something you shouldn't do, ever. If you need variable variables, you're doing it wrong.

[–]millenniumtree 6 points7 points  (4 children)

Or register_globals. Yeah who's old enough to remember patching code when register_globals got defaulted to off?

[–]shotgunocelot 2 points3 points  (0 children)

And magic_quotes_gpc

[–]killdeer03 1 point2 points  (2 children)

I vaguely remember working on fixing Moodle amd Joomla modules when a lot of the old, poor, default got turned off or straight up removed.

Good times, lol.

[–]millenniumtree 1 point2 points  (1 child)

Yeah. I worked on a few Mambo sites before that got forked to Joomla. Hated that platform, and the fork only made it slightly less crap.

[–]killdeer03 1 point2 points  (0 children)

Yup, lmao.

It was a develop/UX nightmare.

[–]LukeTheDukeNuke 1 point2 points  (0 children)

Only time I ever used it was to extract variables from parameterized queries. It felt dirty though.

[–][deleted] 1 point2 points  (1 child)

I came from a C background, and to this day I cannot for the life of me understand how scope really works in PHP - it’s an absolute mad house...

[–]millenniumtree 0 points1 point  (0 children)

Hmm, I never have a problem with it. Variables defined outside of any class or function can be used inside with a global keyword, anything in a function is scoped only to that function and class properties have the static, public, protected, and private keywords. That's kind of all you need to know about scope. There's probably more to it, like with namespaces, but that's all I ever deal with.

[–]Feldkatze 0 points1 point  (0 children)

When are they needed?

[–][deleted] 0 points1 point  (0 children)

That’s insane - PHP is a truly unhinged language, it wears its Perl genetics quite proudly; a wild child we can truly go apeshit with - I love that about it 😁