From 933e0bb76bf130b320e8d7e69643ec859caeb128 Mon Sep 17 00:00:00 2001 From: Philipp Keck Date: Fri, 12 Mar 2021 20:04:42 +0100 Subject: [PATCH] Fix close() under PHP8 Fixes #662 At least on some platforms, maybe always with PHP8, is_resource(curl_init())===false because it returns the new \CurlHandle type instead. --- src/Curl/Curl.php | 7 ++++--- src/Curl/MultiCurl.php | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index eea6ba7..e91b0c2 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -10,7 +10,7 @@ class Curl const VERSION = '8.9.0'; const DEFAULT_TIMEOUT = 30; - public $curl; + public $curl = null; public $id = null; public $error = false; @@ -211,8 +211,9 @@ class Curl */ public function close() { - if (is_resource($this->curl)) { + if ($this->curl !== null) { curl_close($this->curl); + $this->curl = null; } $this->options = null; $this->jsonDecoder = null; @@ -1457,7 +1458,7 @@ class Curl */ public function reset() { - if (function_exists('curl_reset') && is_resource($this->curl)) { + if (function_exists('curl_reset') && $this->curl !== null) { curl_reset($this->curl); } else { $this->curl = curl_init(); diff --git a/src/Curl/MultiCurl.php b/src/Curl/MultiCurl.php index 3219a71..0a59475 100644 --- a/src/Curl/MultiCurl.php +++ b/src/Curl/MultiCurl.php @@ -7,7 +7,7 @@ use Curl\ArrayUtil; class MultiCurl { public $baseUrl = null; - public $multiCurl; + public $multiCurl = null; private $curls = array(); private $activeCurls = array(); @@ -370,8 +370,9 @@ class MultiCurl $curl->close(); } - if (is_resource($this->multiCurl)) { + if ($this->multiCurl !== null) { curl_multi_close($this->multiCurl); + $this->multiCurl = null; } }