From be43e514cef2c70644721539915e6ace71112cba Mon Sep 17 00:00:00 2001 From: nixx Date: Thu, 18 Jun 2026 10:21:44 +0300 Subject: [PATCH 1/3] fix deprecation warning on php 8.4 --- src/Liquid/StandardFilters.php | 8 +++++++- tests/Liquid/OutputTest.php | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Liquid/StandardFilters.php b/src/Liquid/StandardFilters.php index 086b517f..17e1a9a3 100644 --- a/src/Liquid/StandardFilters.php +++ b/src/Liquid/StandardFilters.php @@ -416,6 +416,9 @@ public static function prepend($input, $string) */ public static function remove($input, $string) { + if ($string === null) { + return $input; + } return str_replace($string, '', $input); } @@ -449,7 +452,10 @@ public static function remove_first($input, $string) */ public static function replace($input, $string, $replacement = '') { - return str_replace($string, $replacement, $input); + if ($string === null) { + return $input; + } + return str_replace($string, $replacement === null ? '' : $replacement, $input); } diff --git a/tests/Liquid/OutputTest.php b/tests/Liquid/OutputTest.php index de035b73..f10519da 100644 --- a/tests/Liquid/OutputTest.php +++ b/tests/Liquid/OutputTest.php @@ -224,4 +224,18 @@ public function testFilterArrayNull() $this->assertTemplateResult($expected, $text, []); } + + public function testRemoveWithNull(): void + { + $text = ' {{ best_cars | remove: brand }} '; + + $this->assertTemplateResult(' bmw ', $text, [...$this->assigns, 'brand' => null]); + } + + public function testReplaceWithNull() + { + $text = ' {{ best_cars | replace: brand }} '; + + $this->assertTemplateResult(' bmw ', $text, [...$this->assigns, 'brand' => null]); + } } From bc369d4e3cadd08c532afd706b6a4b138d24dde7 Mon Sep 17 00:00:00 2001 From: nixx Date: Thu, 18 Jun 2026 10:24:00 +0300 Subject: [PATCH 2/3] fix deprecation warning on php 8.4 --- src/Liquid/StandardFilters.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Liquid/StandardFilters.php b/src/Liquid/StandardFilters.php index 17e1a9a3..5a085477 100644 --- a/src/Liquid/StandardFilters.php +++ b/src/Liquid/StandardFilters.php @@ -410,16 +410,13 @@ public static function prepend($input, $string) * Remove a substring * * @param string $input - * @param string $string + * @param string|null $string * * @return string */ public static function remove($input, $string) { - if ($string === null) { - return $input; - } - return str_replace($string, '', $input); + return self::replace($input, $string); } @@ -445,7 +442,7 @@ public static function remove_first($input, $string) * Replace occurrences of a string with another * * @param string $input - * @param string $string + * @param string|null $string * @param string $replacement * * @return string From 89799de6f321cabbeecd93874d99b91ea352e697 Mon Sep 17 00:00:00 2001 From: nixx Date: Thu, 18 Jun 2026 10:26:44 +0300 Subject: [PATCH 3/3] fix deprecation warning on php 8.4 --- src/Liquid/StandardFilters.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Liquid/StandardFilters.php b/src/Liquid/StandardFilters.php index 5a085477..2e7d62e7 100644 --- a/src/Liquid/StandardFilters.php +++ b/src/Liquid/StandardFilters.php @@ -441,9 +441,9 @@ public static function remove_first($input, $string) /** * Replace occurrences of a string with another * - * @param string $input + * @param string|null $input * @param string|null $string - * @param string $replacement + * @param string|null $replacement * * @return string */ @@ -452,7 +452,7 @@ public static function replace($input, $string, $replacement = '') if ($string === null) { return $input; } - return str_replace($string, $replacement === null ? '' : $replacement, $input); + return str_replace($string, (string)$replacement, (string)$input); }