Search code examples
phpphp-extension

API module version


When I build a PHP module extension in C, how can I know the "short" version number of PHP I'm dealing with ? (5.4, 5.3, 5.2, 5.x, ...)

ZEND_MODULE_API_NO only relies on a format like YYYYMMDD (eg: 20060613) !?


Solution

  • The Zend Engine defines a few macros in the php_version.h header for that purpose:

    #define PHP_MAJOR_VERSION 5
    #define PHP_MINOR_VERSION 3
    #define PHP_RELEASE_VERSION 3
    #define PHP_EXTRA_VERSION "-1ubuntu9.7"
    #define PHP_VERSION "5.3.3-1ubuntu9.7"
    #define PHP_VERSION_ID 50303
    

    Per example, if you want to check if the extension is running on 5.3, you'd do:

    if (PHP_VERSION_ID < 50300) {
        // PHP 5.2 or before!
    }