PHP: Hypertext Preprocessor FAIL

April 11th, 2012

One for the geeks. PHP: a fractal of bad design is a positively epic evisceration of the design philosophy behind every geek's fifth- or sixth-favourite scripting language:

There is a whole lot of action at a distance. Consider this code, taken from the PHP docs somewhere.

@fopen('', 'r');

What will it do?

  • If PHP was compiled with --disable-url-fopen-wrapper, it won't work. (Docs don't say what "won't work" means; returns null, throws exception?) Note that this flag was removed in PHP 5.2.5.
  • If allow_url_fopen is disabled in php.ini, this still won't work. (How? No idea.)
  • Because of the @, the warning about the non-existent file won't be printed.
  • But it will be printed if scream.enabled is set in php.ini.
  • Or if scream.enabled is set manually with ini_set.
  • But not if the right error_reporting level isn't set.
  • If it is printed, exactly where it goes depends on display_errors, again in php.ini. Or ini_set.

I can't tell how this innocuous function call will behave without consulting compile-time flags, server-wide configuration, and configuration done in my program. And this is all built in behavior.

I only have cause to use PHP at all because it's what WordPress is built on, so I'm not in a position to evaluate how bad it can get when used to build entire projects. Python seems tidier and more manageable, but in truth I haven't had much call to play around with it beyond writing a couple of scripts last year to customise adding web browser tabs to Instapaper.1 Most of the programming I do these days involves either some combination of Applescript and shell scripts at home, or Visual Basic for Applications2 if I'm at work, so I'm not sure I'm that much better off than all the PHP jockeys out there.

[Via The Null Device]

  1. I'm immensely finicky about trying to preserve page referrer information when I save stuff to read or post later, be it bookmarking pages in Instapaper or Pinboard or sending them to Ecto for me to write a post, so I have various scripts that try to grab the page referrer before passing a page's URL/title/selected text to the destination program or service.
  2. Mostly for Excel, with a bit of Access, Word and Outlook thrown in.

Tags for this entry 

This entry was posted on Wednesday, April 11th, 2012 at 23:18. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.