PHP 8.5: curl_close and curl_share_close functions deprecated because they are no-op in PHP >= 8.0
In PHP 8.0, the Curl extension migrated its resource objects to CurlHandle and CurlShareHandle objects as part of PHP's resource to object transformation.
CurlHandle objects are created by the curl_init function, and prior to PHP 8.0, they can be closed using the curl_close function. Since PHP 8.0, these handles are destroyed automatically using standard PHP object scoping mechanisms, or by explicitly calling unset().
Similarly, CurlShareHandle objects are created by the curl_share_init function, and closed by the curl_share_close function.
In PHP 8.5, curl_close and curl_multi_close functions are deprecated. These functions had no effect since PHP 8.0. Calling them now emits a deprecation notice in PHP 8.5 and later:
$ch = curl_init();
curl_close($ch);
Function curl_close() is deprecated since 8.5, as it has no effect since PHP 8.0
$ch = curl_share_init();
curl_share_close($ch);
Function curl_share_close() is deprecated since 8.5, as it has no effect since PHP 8.0
The similarly named curl_multi_close function is not deprecated.
Recommended Replacement
Because the curl_close and curl_share_close functions no longer have any effect in PHP 8.0 and later, they can be removed without any functionality impact:
If it is necessary to explicitly close a CurlHandle or a CurlShareHandle object, call unset, or set the object to null:
- curl_close($ch);
+ if (PHP_VERSION_ID >= 80000) {
+ unset($ch);
+ } else {
+ curl_close($ch);
+ }
- curl_share_close($ch);
+ if (PHP_VERSION_ID >= 80000) {
+ unset($ch);
+ } else {
+ curl_share_close($ch);
+ }
If compatibility with older PHP versions is not necessary, this replacement can be simplified as follows:
- curl_close($ch);
+ unset($ch);
- curl_share_close($ch);
+ unset($ch);