Imarc

The PHP We're Glad to Have Forgotten Kevin Hamer

Written on: November 10th, 2014 in engineering

PHP is nearly a twenty year old language. While its certainly not the oldest, it's come a long way from where it started. HHVM  and PHP 5.6 are stripping a lot of the junk that doesn't belong in PHP, as even in PHP 5.5 there's still a lot of things that should be avoided.

Here's a 100% functional, sample PHP file (given that you have asp_tags on) that uses many of the worst things PHP still has, just for fun:

Some highlights:

  • While PHP does throw a notice, I'll never really be a fan of the fact that PHP will happily treat unquoted strings as strings if they don't match a constant.
  • goto seemed like a great idea back in third grade when I was writing QBasic, but it just leads to unstructured code.
  • While I'm sure there are reasons why PHP supported ASP-style and script tags, being able to mix them (and worse, open with one style and close with another) is ridiculous.
  • In general, extract is a bad idea. Especially how I used it (on $_REQUEST) as any variable in the script is susceptible to being overridden.
  • Variable variables are a neat trick, but in practice, there's going to be clearer ways.

All languages have good parts and bad parts, and PHP is no exception. Good code is explicit, sticks to the good parts, and focuses on clarity.

Share:

Let's Talk.