From 7c578f499a43942ed27cde0ddf0c51c66467e042 Mon Sep 17 00:00:00 2001 From: dahn15 Date: Tue, 6 Oct 2026 15:34:16 +0200 Subject: [PATCH] Refactor Curl execution and error handling curl_close() has had no effect since PHP 8.0 and is deprecated as of PHP 8.5, which triggers an E_DEPRECATED notice on every request. The call is now only made on PHP < 8.0, so PHP 7.4 support is preserved. Also changed the curl_exec() check to `=== false`, since an empty response body (e.g. 204 No Content) previously threw a CurlException with error code 0. --- src/CurlClient.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CurlClient.php b/src/CurlClient.php index 9276719..d8ab4ec 100644 --- a/src/CurlClient.php +++ b/src/CurlClient.php @@ -49,13 +49,17 @@ public function request(string $method, string $url, ?array $data = null) curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); - if (!$response = curl_exec($curl)) { + $response = curl_exec($curl); + + if ($response === false) { throw new CurlException(curl_errno($curl), curl_error($curl)); } $httpStatus = curl_getinfo($curl, CURLINFO_HTTP_CODE); - curl_close($curl); + if (PHP_VERSION_ID < 80000) { + curl_close($curl); + } return [$response, $httpStatus]; }