Thursday, August 27, 2015
At the computers of craziness
I throw together things until it works then I move on. The real programmers will say "yeah it works but you're leaking memory everywhere. Perhaps we should fix that." I'll just restart apache every 10 requests.
I am not a fan of PHP for a variety of reasons, and it doesn't help that the author of PHP says the scariest things a programmer can say and people still use his stuff.
True story: back in 1997 or 1998, Smirk came up to me with two thick printouts and asked me for my opinion. The printouts were manuals for two different HTML processors, one called MetaHTML and the other one PHP. Even back then, I had an uneasy feeling about PHP and said we should go with MetaHTML (the website no longer exists and good luck trying to search for “MetaHTML”).
But little did I realize the eldritch horrors lurking
in the depths of R'lyeh PHP:
And if that's too simple, then just make the condition random:
class FooClass { } $foo = new FooClass(); $foo->bar = "qux"; $thing = "bar"; $qux = "th"; $grault = "ing"; $corge = "gnu"; echo $foo->${${$foo->bar}.${(rand(0, 9)<5)?grault:''}}, "\n";Yeah this will print
qux
half the time, and crash the other half. Want to add equality tests? knock yourself out:($foo->${${$foo->bar}.((${pouet}.${machin}===$pouet.${machin})?${machin}:${$pouet.$machin})});And that's where the second realization hits: you know how
foo
is just a string right? Then wouldn'tfoo()
be "a string with parens"?Well it happens that no:
function foo() { return "foo"; } echo "foo"(); $ php test.php Parse error: syntax error, unexpected '(', expecting ',' or ';' in test.php on line 4Unless you put the string in a variable itself:
function foo() { return "foo"; } $bar = "foo"; echo $bar();this will print
foo
. That's actually what PHP's owncreate_function
does. And yes, I can see the dread in your eyes already.Your fears are real.
Via Hacker News, masklinn comments on 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.
Run now! Look not at this page! Spare your sanity! Aiiieeeeeeeeeeeeeee eeeeeeeeeeeeeeeeeeee—