Check Your PHP Version

(2018)

You can check your PHP version from the command line like this.

php --version

You can also check within PHP code itself, by using the following function:

// "7.1.15"
phpversion();

My installation currently outputs "7.1.15", but note that the results are somewhat system specific. According to the documentation, the output string may contain extra text in addition to the version number.

This function can also tell you the version number of an installed module, for example:

// "1.13.5"
phpversion('zip');

This will return the version number of the installed ZIP module, of false if the module is missing.

A related interesting function is version_compare(), which can tell you whether the installed PHP meets a minimum version number. This can be used to provide alternative implementations of a function/feature, or to prevent code from running on extremely old versions of PHP.

if (version_compare(PHP_VERSION, '7.0.0') >= 0) {
    echo ("Yay, modern PHP\n");
} else if (version_compare(PHP_VERSION, '5.6.0') >= 0) {
    echo ("Probably tolerable! Supported thru December 2018\n");
} else if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
    echo ("Not officially supported\n");
} else {
    echo ("Run away screaming\n");
}