Skip to content

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

Open
semhoun wants to merge 3 commits intophptg:masterfrom
semhoun:fix/curl_close_deprecation
Open

Fix deprecated curl_close() warning on PHP 8.5+#194
semhoun wants to merge 3 commits intophptg:masterfrom
semhoun:fix/curl_close_deprecation

Conversation

@semhoun
Copy link
Copy Markdown

@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)

@semhoun semhoun force-pushed the fix/curl_close_deprecation branch from ff3daea to 1c86272 Compare April 10, 2026 18:12
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