Why you should NOT use short tags in PHP

Where’s My Damn Emulator?

So I was trying to find a good SNES emulator for Mac. I read somewhere that Snes9x works for OSX, so I went to the site and then the downloads page to find one to… well, to download. The page started out “Here is a list of all the known available mirrors for Snes9x…”, but then it was an empty list.

I thought of two possibilities. Either the list contains exactly zero available mirrors, or something is wrong with the page. It struck me as rather odd that the site would put up an empty list of download mirrors for its own product, so I did some investigative research to check out possibility #2.

Note that the site is built in PHP. Here’s the non-hyperlinked URL for the downloads page: http://www.snes9x.com/downloads.php

Here’s a snippet from the page source:

Here is a list of all the known available mirrors for Snes9x. If a mirror is
not listed on this page, it either does not exist or the web peon doesn't know it exists.

Notice the foreach loop and the stuff? That’s the culprit.

PHP – A Short Word on Tags

PHP “tags” are opening and closing bits of code that let the machine know when text should be evaluated as PHP code, and when it’s not code (e.g. just “normal” text).

This is a standard opening PHP tag:

...and this is a closing tag:

The idea is that everything in between the opening & closing tags is evaluated as PHP code & executed (in this case by the web server).

Also, note that when viewing a site built on PHP, you will never be able to see the PHP code! The web server will execute that code, then spit out the results to your screen. The results are what you see, only after the code is executed. Enter short tags...

Short Tags Suck Ass and Should Die

Remember the standard opening tag in PHP? Well, one day some genius came along and decided that he could save a whole 3 fucking keystrokes by just removing the letters "php", so the optional "short tag" was invented. Now, "<?php" could be shortened to just "<?". Absolute genius.

Then he decided to improve upon that and add the "echo shortcut", which is just the short opening tag followed by an equals sign. It's used like the echo function.

Here's the standard opening PHP tag, echo statement, and closing tag:

... and for comparison, the echo shortcut:

The problem is, not all servers support PHP short tags. So code that's working fine on one server might break when moved or copied to another server. Or maybe the sysadmin decides to disable short tags for whatever reason. Or a new version of PHP is installed.

Then crap like the above happens, and Nathan doesn't get his list of download mirrors for Snes9x, and the world is a bit worse of a place in general. Don't be an asshole. Don't use short tags.

Also, I've written a script (in Perl) called php_fixxer.pl. If you have PHP code with short tags, please backup your code, then download this & run it on all your code. It's called "fixxer" because if it has short tags, then it's as good as broken.

Oh, by the way: I'm not responsible for anything you screw up with this script. I told you to back up your code anyway. I do, however, accept full responsibility for any and all productive enhancements made possible by use of it.


Oh yeah, back to the above site... the page pretty much works, just one part of it is broken. Unfortunately, it's the part that's the reason for the existence of the page. Since this is the only PHP code that I am able to see from my browser {see note above if that doesn't make sense}, that probably means:

1) The whole file doesn't make use of short tags, just some of it.
2) If they convert these to standard PHP tags (no shortcuts), then this page should start working again, and I will be able to see my download mirror URLs.