Search code examples
cphp-extensionphp-internalsphp

Expose version of extension in phpinfo() output


When writing custom extensions for PHP, you usually define a version string in the header file of your extension, e.g. something like

#define PHP_MYEXT_VERSION "0.1.0"

PHP will then use this to provide information about the extension's version when calling phpversion('myext') in userland PHP.

However, the version string will not be rendered in the output of phpinfo() by default. Some extensions, like ext/json, do have their version listed in the output of phpversion() though.

How can the version be exposed in phpinfo()?


Solution

  • You can define which information is displayed for your extension in the output of phpinfo() by providing the PHP_MINFO_FUNCTION function in your myext.c file.

    Example from ext/json:

    /* {{{ PHP_MINFO_FUNCTION
    */
    static PHP_MINFO_FUNCTION(json)
    {
        php_info_print_table_start();
        php_info_print_table_row(2, "json support", "enabled");
        php_info_print_table_row(2, "json version", PHP_JSON_VERSION);
        php_info_print_table_end();
    }
    /* }}} */
    

    This will then produce an output like this:

    json
    
    json support => enabled
    json version => 1.4.0