From f1376e17cabc5381d0562d4fb2b7a51406e4188e Mon Sep 17 00:00:00 2001 From: twinh Date: Sun, 12 Nov 2023 17:54:15 +0800 Subject: [PATCH] fix: PHP 8.1 Passing null to parameter of type string is deprecated --- lib/Http.php | 2 +- lib/IsContains.php | 3 ++- lib/IsDir.php | 3 ++- lib/IsExists.php | 3 ++- lib/Req.php | 2 +- lib/Res.php | 4 ++-- lib/WeChatApp.php | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/Http.php b/lib/Http.php index 3d8ffa474..a0f9d6e03 100644 --- a/lib/Http.php +++ b/lib/Http.php @@ -921,7 +921,7 @@ protected function prepareCurlOptions() if ($this->cookies) { $cookies = []; foreach ($this->cookies as $key => $value) { - $cookies[] = $key . '=' . rawurlencode($value); + $cookies[] = $key . '=' . rawurlencode($value ?? ''); } $opts[\CURLOPT_COOKIE] = implode('; ', $cookies); } diff --git a/lib/IsContains.php b/lib/IsContains.php index d88221b37..59c723257 100644 --- a/lib/IsContains.php +++ b/lib/IsContains.php @@ -47,7 +47,8 @@ public function __invoke($input, $search = null, $regex = false) */ protected function doValidate($input) { - if (!$this->isString($input)) { + $input = $this->toString($input); + if (null === $input) { $this->addError('notString'); return false; } diff --git a/lib/IsDir.php b/lib/IsDir.php index fe749681f..2fd4c3299 100644 --- a/lib/IsDir.php +++ b/lib/IsDir.php @@ -27,7 +27,8 @@ class IsDir extends BaseValidator */ protected function doValidate($input) { - if (!$this->isString($input)) { + $input = $this->toString($input); + if (null === $input) { $this->addError('notString'); return false; } diff --git a/lib/IsExists.php b/lib/IsExists.php index d9216bba0..097b59705 100644 --- a/lib/IsExists.php +++ b/lib/IsExists.php @@ -27,7 +27,8 @@ class IsExists extends BaseValidator */ protected function doValidate($input) { - if (!$this->isString($input)) { + $input = $this->toString($input); + if (null === $input) { $this->addError('notString'); return false; } diff --git a/lib/Req.php b/lib/Req.php index 86d64572e..6b38d676e 100644 --- a/lib/Req.php +++ b/lib/Req.php @@ -842,7 +842,7 @@ public function getIterator(): \Traversable */ public function accept($mine) { - return 0 === strpos($this->getServer('HTTP_ACCEPT'), $mine); + return 0 === strpos($this->getServer('HTTP_ACCEPT', ''), $mine); } /** diff --git a/lib/Res.php b/lib/Res.php index 341ab28af..28dd23058 100644 --- a/lib/Res.php +++ b/lib/Res.php @@ -591,7 +591,7 @@ public function redirect($url = null, $statusCode = 302, $options = []) $this->setOption($options); // The variables for custom redirect view - $escapedUrl = htmlspecialchars($url, \ENT_QUOTES, 'UTF-8'); + $escapedUrl = $url ? htmlspecialchars($url, \ENT_QUOTES, 'UTF-8') : $url; $wait = (int) $this->redirectWait; // Location header does not support delay @@ -716,7 +716,7 @@ public function download($file = null, array $downloadOptions = []) $name = rawurlencode($name); // For IE - $userAgent = $this->request->getServer('HTTP_USER_AGENT'); + $userAgent = $this->request->getServer('HTTP_USER_AGENT', ''); if (preg_match('/MSIE ([\w.]+)/', $userAgent)) { $filename = '=' . $name; } else { diff --git a/lib/WeChatApp.php b/lib/WeChatApp.php index 6a82f9dae..88885cad4 100644 --- a/lib/WeChatApp.php +++ b/lib/WeChatApp.php @@ -1029,7 +1029,7 @@ protected function arrayToXml(array $array, SimpleXMLElement $xml = null) } else { $child = $xml->addChild($key); $node = dom_import_simplexml($child); - $node->appendChild($node->ownerDocument->createCDATASection($value)); + $node->appendChild($node->ownerDocument->createCDATASection($value ?? '')); } } }