Check requirements

03 January 2014

If your letting others use the scripts you write, do try to make the scripts do som basic sanity check before letting them run. If your script need a PHP version later than PHP 5.2 then let the script check for this requirement by doing something like this:

if ( version_compare(PHP_VERSION, '5.2', '<') ) {
    exit("ERROR: The script requires PHP 5.2 or greater. The current version of PHP is ".PHP_VERSION.".");
}

While some users could debug what’s wrong with your script, may can’t and will end up in an endless Google search - and may never discover why your script wouldn’t work in their setup. Aside from checking the version of the core scripting language you should also check if modules and/or extensions your script require is available - most programming language do actually have facilities available to do just that.