From 84cfdfb0c33b9f16aaec3b858a64097e0e6fc5c6 Mon Sep 17 00:00:00 2001 From: Juan Cruz Vincenti Date: Tue, 9 Jan 2024 16:35:08 -0300 Subject: [PATCH] Fix some PHP 8.1 deprecation warnings * Fix passing null to str_replace and preg_replace in HttpSocket * Fix dynamic props usage in ModelValidator * Fix passing null to rawurlencode in CakeRoute --- lib/Cake/Model/ModelValidator.php | 1 + lib/Cake/Network/Http/HttpSocket.php | 8 ++++---- lib/Cake/Routing/Route/CakeRoute.php | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Cake/Model/ModelValidator.php b/lib/Cake/Model/ModelValidator.php index 24a453b53..17f402649 100644 --- a/lib/Cake/Model/ModelValidator.php +++ b/lib/Cake/Model/ModelValidator.php @@ -31,6 +31,7 @@ App::uses('Hash', 'Utility'); * @package Cake.Model * @link https://book.cakephp.org/2.0/en/data-validation.html */ +#[\AllowDynamicProperties] class ModelValidator implements ArrayAccess, IteratorAggregate, Countable { /** diff --git a/lib/Cake/Network/Http/HttpSocket.php b/lib/Cake/Network/Http/HttpSocket.php index 624b97a25..a02d71db5 100644 --- a/lib/Cake/Network/Http/HttpSocket.php +++ b/lib/Cake/Network/Http/HttpSocket.php @@ -720,7 +720,7 @@ class HttpSocket extends CakeSocket { return false; } - $uri['path'] = preg_replace('/^\//', null, $uri['path']); + $uri['path'] = preg_replace('/^\//', '', $uri['path']); $uri['query'] = http_build_query($uri['query'], '', '&'); $uri['query'] = rtrim($uri['query'], '='); $stripIfEmpty = array( @@ -732,16 +732,16 @@ class HttpSocket extends CakeSocket { foreach ($stripIfEmpty as $key => $strip) { if (empty($uri[$key])) { - $uriTemplate = str_replace($strip, null, $uriTemplate); + $uriTemplate = str_replace($strip, '', $uriTemplate); } } $defaultPorts = array('http' => 80, 'https' => 443); if (array_key_exists($uri['scheme'], $defaultPorts) && $defaultPorts[$uri['scheme']] == $uri['port']) { - $uriTemplate = str_replace(':%port', null, $uriTemplate); + $uriTemplate = str_replace(':%port', '', $uriTemplate); } foreach ($uri as $property => $value) { - $uriTemplate = str_replace('%' . $property, $value, $uriTemplate); + $uriTemplate = str_replace('%' . $property, (string)$value, $uriTemplate); } if ($uriTemplate === '/*') { diff --git a/lib/Cake/Routing/Route/CakeRoute.php b/lib/Cake/Routing/Route/CakeRoute.php index 8149ce39a..0ac38d2bf 100644 --- a/lib/Cake/Routing/Route/CakeRoute.php +++ b/lib/Cake/Routing/Route/CakeRoute.php @@ -498,7 +498,7 @@ class CakeRoute { } if (is_array($params['pass'])) { - $params['pass'] = implode('/', array_map('rawurlencode', $params['pass'])); + $params['pass'] = implode('/', array_map(fn($param) => rawurlencode((string)$param), $params['pass'])); } $namedConfig = Router::namedConfig();