Why PHP will never give way to Go, Rust, Ruby, Python, etc….

PHP is an incredible language I fell in love with sometime around 2000. It simplified my Weblibs, which I had originally written as a bunch of Perl CGIs. I can’t recall the details, but I assure you that PHP was an amazing choice which improved the app tenfold. It definitely wasn’t due to my Perl skills being atrocious, or the benefit of hindsight when doing a code rewrite.

And then I was able to get fairly decent at PHP as I built more and more of my site on it. It’s truly an icon in Nerdbucket history!

One of the wonderful things about it is how its type system is loose. Really, truly loose. Looser than YERMOM, if you can believe it. Unlike silly languages that say, “Hey, you can’t call object methods on a variable that has yet to be declared!”, PHP will just keep chugging along without a care. It’s so darn cute with its “ignorance is bliss” mentality.

For you ridiculous “oh noes I need compilerz” twits, let me show you just how amazeballs this shit is.

Let’s say you’ve got an object which has a method which tells you in which directory it lives, relative to some data path. The object is meant to be able to read and write to anything under the data path, and when purged, it can delete its subdirectory recursively.

rp));
}

$a = new A();
$a->rp = "subdir";
$deletedir = fp($a);

// ... Do stuff with $a

// Right here we run the delete, but this just shows what will happen
print "rm -rf $deletedir\n";

Note the output:

rm -rf /var/local/myapp/objects/subdir

Time passes, and somebody moves that fp() function into the class, but makes a tiny mistake:

rp));
  }
}

$a = new A();
$a->rp = "subdir";
$deletedir = $a->fp();

// ... Do stuff with $a

// Right here we run the delete, but this just shows what will happen
print "rm -rf $deletedir\n";

The output here is precisely what any good developer would want:

PHP Notice:  Undefined variable: a in /home/nerdbuc/blog/test2.php on line 18
PHP Notice:  Trying to get property of non-object in /home/nerdbuc/blog/test2.php on line 18
rm -rf /var/local/myapp/objects/

Two notice-level log messages, and destruction of all kinds of object data. I like that PHP considers this a notice, because it’s not pushing shit down my throat like SOME languages.

Hey there, fella, looks like you’re generating a string for something. Wonder if it’s important for stuff. Hmm. Well anyway, just FYI when you get time, I don’t know what $a is, so I’m going to assume by $a->rp, what you really meant was NULL. kthxbye, love, PHP

Just to avoid stupid Q&A on this post, here’s the conversation us PHP defenders will have with dipshits whose girlfriends are compilers.

Compiler Nazi (CN): My compiler would have caught that and I wouldn’t have had any broken data. The code wouldn’t have run at all!

Me: STFU NOOB! Go back to the 1980s! You’re just too dumb to properly write tests and catch this in your ten-minute integration test suite.

CN: But my compiler is way faster than a test suite. Besides, even in Perl or Python or Ruby or hell, bash with set -eu, at least I could prevent the obviously broken code from running.

Me: ME FUCKING TOO, LOSER: http://stackoverflow.com/a/3193084/468391

CN: Wait… so you’re going to have to write an error handler that catches notices, checks the error string, and pukes when the string matches a pattern? That’s a huge hack! It’s not elegant or maintainable.

Me: JUST LIKE YERMOM!

CN: Ummm… what?

It should be pretty clear how stupid it is to defend strongly typed languages now.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.