PHP 8.4: Curl: curl_version() feature_list support

Version8.4
TypeNew Feature

The curl_version function in the Curl extension returns an associative array containing Curl version and build information. This includes Curl version, SSL library name and version, Brotli and libz versions, a list of protocols supported by the Curl build, and a bitmask of all features supported by Curl.

The bitmask of features is not intuitive to discover and easily check if a particular feature (such as HTTP/2, HSTS, etc) is supported in Curl.

In PHP 8.4, the curl_version function returns an additional array key named feature_list, with an array of Curl features and whether they are supported or not.

curl_version();
[
    "version_number" => 524801,
    "age" => 10,
    "features" => 1438631837,
+    "feature_list" => [
+      "AsynchDNS" => true,
+      "CharConv" => false,
+      "Debug" => false,
+      // ...
+      "HTTP2" => true,
+      "HTTPS_PROXY" => true,
+      "BROTLI" => true,
+      "ALTSVC" => true,
+      "HTTP3" => false,
+      "ZSTD" => true,
+      "HSTS" => true,
+      // ...
+    ],
    "ssl_version_number" => 0,
    "version" => "8.2.1",
    "host" => "x86_64-pc-linux-gnu",
    // ...
  ]

The list of features is a simple key-value array where the key is the name of the feature, and the value is always a boolean value indicating whether that feature is supported or not.

This makes it more readable when inspecting if certain features are supported in Curl.

For example, to check if HTTP/3 is supported, it required checking the availability of the CURL_VERSION_ constant, and checking the features bitmask. In PHP 8.4 and later, it is only involves checking the feature_list array:

  // Check if HTTP/3 is supported in Curl
- defined('CURL_VERSION_HTTP3') && (curl_version()['features'] & CURL_VERSION_HTTP3 === CURL_VERSION_HTTP3)
+ !empty(curl_version()['feature_list']['HTTP3']);

Related Changes

Backward Compatibility Impact

The curl_version() function calls in PHP 8.4 and later return a new feature_list value. This functionality cannot be ported to older PHP versions.

For cross-version compatibility in checking if a certain Curl feature is available, inspect whether the relevant CURL_VERSION_* constant is declared, and if the curl_version()['feature'] bitmask contains that value.


curl_version Implementation