Skip to content

Fix deprecated curl_close() warning on PHP 8.5+#194

Merged
vjik merged 7 commits intophptg:masterfrom
semhoun:fix/curl_close_deprecation
Apr 13, 2026
Merged

Fix deprecated curl_close() warning on PHP 8.5+#194
vjik merged 7 commits intophptg:masterfrom
semhoun:fix/curl_close_deprecation

Conversation

@semhoun
Copy link
Copy Markdown
Contributor

@semhoun semhoun commented Apr 9, 2026

Summary

Fixes the deprecation warning Function curl_close() is deprecated since 8.5, as it has no effect since PHP 8.0 that appears when running on PHP 8.5 or higher.

Problem

Since PHP 8.0, cURL handles (CurlHandle objects) are automatically closed when they are no longer referenced or when the script ends. The explicit curl_close() function call became redundant.

In PHP 8.5, curl_close() is officially deprecated and emits a warning:

Deprecated: Function curl_close() is deprecated since 8.5, as it has no effect since PHP 8.0

Solution

Add a version check to only call curl_close() on PHP versions older than 8.0:

public function close(CurlHandle $handle): void
{
    if (\PHP_VERSION_ID < 80000) {
        curl_close($handle);
    }
}

Backward Compatibility

This change maintains full backward compatibility:

PHP Version Behavior
PHP < 8.0 curl_close() is called as before (required for resource cleanup)
PHP 8.0 - 8.4 No-op (handles auto-close, no deprecation warning)
PHP 8.5+ No-op (avoids deprecation warning, handles auto-close)

Comment thread src/Curl/Curl.php Outdated
@semhoun semhoun force-pushed the fix/curl_close_deprecation branch from ff3daea to 1c86272 Compare April 10, 2026 18:12
@vjik vjik merged commit 2589096 into phptg:master Apr 13, 2026
18 checks passed
@vjik
Copy link
Copy Markdown
Member

vjik commented Apr 13, 2026

@semhoun Thanks for contribute!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants