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.
“Rasmus Lerdorf [1]”

I am not a fan of PHP [2] for a variety of reasons [3], and it doesn't help that the author of PHP says the scariest things a programmer can say [4] 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 (HyperText Markup Language) 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 [5] lurking in the depths of [DELETED-R'lyeh-DELETED] 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't foo() 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 4
```
Unless 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 own create_function does. And yes, I can see the dread in your eyes already.
Your fears are real.

Via Hacker News [6], “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. [7]”

Run now! Look not at this page! Spare your sanity! Aiiieeeeeeeeeeeeeee­ eeeeeee­eeeeee­eeee­eee—

[1] https://en.wikipedia.org/wiki/Rasmus_Lerdorf

[2] http://pnp.net/

[3] https://www.google.com/search?q=php+site%3Aboston.conman.org

[4] https://en.wikiquote.org/wiki/Rasmus_Lerdorf

[5] https://lovecraftsoftware.wordpress.com/

[6] https://news.ycombinator.com/item?id=1805729

[7] https://www.reddit.com/r/programming/comments/dst56/today_i_learned_about_php_variable_variables/c12np38

Gemini Mention this post

Contact the author