From b41a3824d9e1f1d3b12bcc5f7725c2c85d235885 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20Semhoun?= Date: Thu, 9 Apr 2026 16:17:56 +0200 Subject: [PATCH 1/6] Fix deprecated curl_close() warning on PHP 8.5+ --- src/Curl/Curl.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index ab03f25b..e127e5aa 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -23,7 +23,9 @@ final class Curl implements CurlInterface { public function close(CurlHandle $handle): void { - curl_close($handle); + if (\PHP_VERSION_ID < 80000) { + curl_close($handle); + } } public function exec(CurlHandle $handle): ?string From 1c862720d20ba35d7eb7ae0b5f7b4b46e74108d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nathana=C3=ABl=20Semhoun?= Date: Fri, 10 Apr 2026 20:11:46 +0200 Subject: [PATCH 2/6] Remove call to curl_close --- src/Curl/Curl.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index e127e5aa..6174206d 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -23,9 +23,6 @@ final class Curl implements CurlInterface { public function close(CurlHandle $handle): void { - if (\PHP_VERSION_ID < 80000) { - curl_close($handle); - } } public function exec(CurlHandle $handle): ?string From 40ac924834693644f0cfdff1a8040b741dacd2f0 Mon Sep 17 00:00:00 2001 From: semhoun <54236487+semhoun@users.noreply.github.com> Date: Fri, 10 Apr 2026 18:13:05 +0000 Subject: [PATCH 3/6] Apply PHP CS Fixer and Rector changes (CI) --- src/Curl/Curl.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 6174206d..1c236feb 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -7,7 +7,6 @@ use CurlHandle; use CurlShareHandle; -use function curl_close; use function curl_errno; use function curl_error; use function curl_exec; @@ -21,9 +20,7 @@ */ final class Curl implements CurlInterface { - public function close(CurlHandle $handle): void - { - } + public function close(CurlHandle $handle): void {} public function exec(CurlHandle $handle): ?string { From 1fc6e0fc95d14ff7ab7e51c46700fd9d70ef7734 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Mon, 13 Apr 2026 11:05:16 +0300 Subject: [PATCH 4/6] improve --- composer.json | 2 +- src/Curl/Curl.php | 2 -- src/Curl/CurlInterface.php | 2 -- src/Transport/CurlTransport.php | 24 +++++++------------ tests/Curl/CurlMock.php | 11 --------- .../CurlTransportDownloadFileTest.php | 13 ---------- .../CurlTransport/CurlTransportTest.php | 13 ---------- 7 files changed, 10 insertions(+), 57 deletions(-) diff --git a/composer.json b/composer.json index 84a9a216..f2d901d6 100644 --- a/composer.json +++ b/composer.json @@ -77,7 +77,7 @@ "infection": "infection --threads=max", "psalm": "psalm", "rector": "rector", - "test": "phpunit", + "test": "phpunit --display-deprecations", "test-real": "phpunit --group=realApi" } } diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 1c236feb..db02ae57 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -20,8 +20,6 @@ */ final class Curl implements CurlInterface { - public function close(CurlHandle $handle): void {} - public function exec(CurlHandle $handle): ?string { $result = curl_exec($handle); diff --git a/src/Curl/CurlInterface.php b/src/Curl/CurlInterface.php index 995f0d42..88db64f9 100644 --- a/src/Curl/CurlInterface.php +++ b/src/Curl/CurlInterface.php @@ -12,8 +12,6 @@ */ interface CurlInterface { - public function close(CurlHandle $handle): void; - /** * @throws CurlException */ diff --git a/src/Transport/CurlTransport.php b/src/Transport/CurlTransport.php index 9eb93c0f..b95bfeaf 100644 --- a/src/Transport/CurlTransport.php +++ b/src/Transport/CurlTransport.php @@ -101,8 +101,6 @@ public function downloadFile(string $url): mixed $this->curl->exec($curl); } catch (CurlException $exception) { throw new DownloadFileException($exception->getMessage(), previous: $exception); - } finally { - $this->curl->close($curl); } rewind($stream); @@ -117,20 +115,16 @@ private function send(array $options): ApiResponse $curl = $this->curl->init(); - try { - $this->curl->setopt_array($curl, $options); + $this->curl->setopt_array($curl, $options); + + /** + * @var string $body `curl_exec` returns string because `CURLOPT_RETURNTRANSFER` is set to `true`. + */ + $body = $this->curl->exec($curl); - /** - * @var string $body `curl_exec` returns string because `CURLOPT_RETURNTRANSFER` is set to `true`. - */ - $body = $this->curl->exec($curl); - - $statusCode = $this->curl->getinfo($curl, CURLINFO_HTTP_CODE); - if (!is_int($statusCode)) { - $statusCode = 0; - } - } finally { - $this->curl->close($curl); + $statusCode = $this->curl->getinfo($curl, CURLINFO_HTTP_CODE); + if (!is_int($statusCode)) { + $statusCode = 0; } return new ApiResponse($statusCode, $body); diff --git a/tests/Curl/CurlMock.php b/tests/Curl/CurlMock.php index 719817ae..9fc58f1f 100644 --- a/tests/Curl/CurlMock.php +++ b/tests/Curl/CurlMock.php @@ -16,7 +16,6 @@ final class CurlMock implements CurlInterface { private ?array $options = null; private array $shareOptions = []; - private int $countCallOfClose = 0; public function __construct( private readonly string|Throwable $execResult = '', @@ -24,11 +23,6 @@ public function __construct( private readonly ?Throwable $initException = null, ) {} - public function close(CurlHandle $handle): void - { - $this->countCallOfClose++; - } - public function exec(CurlHandle $handle): string { if ($this->execResult instanceof Throwable) { @@ -74,9 +68,4 @@ public function getShareOptions(): array { return $this->shareOptions; } - - public function getCountCallOfClose(): int - { - return $this->countCallOfClose; - } } diff --git a/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php b/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php index 2ac683d2..d54a1874 100644 --- a/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php +++ b/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php @@ -71,17 +71,4 @@ public function testExecException(): void assertSame('test', $exception->getMessage()); assertSame($execException, $exception->getPrevious()); } - - public function testCloseOnException(): void - { - $curl = new CurlMock(new RuntimeException()); - $transport = new CurlTransport(curl: $curl); - - try { - $transport->downloadFile('https://example.test/hello.jpg'); - } catch (Throwable) { - } - - assertSame(1, $curl->getCountCallOfClose()); - } } diff --git a/tests/Transport/CurlTransport/CurlTransportTest.php b/tests/Transport/CurlTransport/CurlTransportTest.php index 0d7b6873..c58345e3 100644 --- a/tests/Transport/CurlTransport/CurlTransportTest.php +++ b/tests/Transport/CurlTransport/CurlTransportTest.php @@ -158,19 +158,6 @@ public function testSeekableResource(): void ); } - public function testCloseOnException(): void - { - $curl = new CurlMock(new RuntimeException()); - $transport = new CurlTransport(curl: $curl); - - try { - $transport->get('getMe'); - } catch (Throwable) { - } - - assertSame(1, $curl->getCountCallOfClose()); - } - public function testShareOptions(): void { $curl = new CurlMock( From 1b8a7d73e97c531feeb6f03910d22500f8a21148 Mon Sep 17 00:00:00 2001 From: vjik <525501+vjik@users.noreply.github.com> Date: Mon, 13 Apr 2026 08:06:11 +0000 Subject: [PATCH 5/6] Apply PHP CS Fixer and Rector changes (CI) --- tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php | 1 - tests/Transport/CurlTransport/CurlTransportTest.php | 2 -- 2 files changed, 3 deletions(-) diff --git a/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php b/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php index d54a1874..990d5eba 100644 --- a/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php +++ b/tests/Transport/CurlTransport/CurlTransportDownloadFileTest.php @@ -6,7 +6,6 @@ use CurlShareHandle; use PHPUnit\Framework\TestCase; -use RuntimeException; use Throwable; use Phptg\BotApi\Curl\CurlException; use Phptg\BotApi\Tests\Curl\CurlMock; diff --git a/tests/Transport/CurlTransport/CurlTransportTest.php b/tests/Transport/CurlTransport/CurlTransportTest.php index c58345e3..8a9db0be 100644 --- a/tests/Transport/CurlTransport/CurlTransportTest.php +++ b/tests/Transport/CurlTransport/CurlTransportTest.php @@ -7,8 +7,6 @@ use CurlShareHandle; use CURLStringFile; use PHPUnit\Framework\TestCase; -use RuntimeException; -use Throwable; use Phptg\BotApi\Tests\Curl\CurlMock; use Phptg\BotApi\Transport\CurlTransport; use Phptg\BotApi\Type\InputFile; From bafa5dd13e072f6607974f6c677ce228e02fada3 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Mon, 13 Apr 2026 11:09:55 +0300 Subject: [PATCH 6/6] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c6c9f3a..3c06e158 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Telegram Bot API for PHP Change Log +## 0.18.2 under construction + +- Enh #194: Remove deprecated `curl_close()` call in `CurlTransport`. + ## 0.18.1 April 5, 2026 - Bug #192: Add missed `certificate` parameter to `SetWebhook` method.