Check PHP version

From WordPress 3.2, PHP 5.2.4 is required for it to run. While developing plugins for this version you might need to check that the PHP version is up to date.

PHP has a built in function for checking versions, namely version_compare(). With this function, you can compare different version numbers, and PHP_VERSION is a constant you can use to get the current PHP version, which is just what we need for this check.

Code Snippet:

if ( version_compare(PHP_VERSION, '5.2.4', '<') ) {
    wp_die('PHP 5.2.4 is required.');

Posted in Conditional