From 6663f700dec61107735f05f03af6719d5e3cac3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?= <235185+goba@users.noreply.github.com> Date: Sat, 24 Oct 2026 21:21:32 +0200 Subject: [PATCH] Fix PHP 8.5 deprecation in html_cva() when a recipe value is null --- CHANGELOG | 1 + extra/html-extra/Cva.php | 2 +- extra/html-extra/Tests/CvaTest.php | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index e7ff0fa96b7..3285bcab97a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ # 3.31.0 (2026-XX-XX) + * Fix a PHP 8.5 deprecation in `html_cva()` when a recipe value is `null` * Add the `collate` function to `twig/intl-extra` to compare strings in the alphabetical order of a locale * Fix reading an attribute through its getter initializing a lazy object when the property is not public * Fix compiled float literals depending on the `serialize_precision` ini setting diff --git a/extra/html-extra/Cva.php b/extra/html-extra/Cva.php index 5d5bd50acbc..f0791c06113 100644 --- a/extra/html-extra/Cva.php +++ b/extra/html-extra/Cva.php @@ -95,7 +95,7 @@ public function apply(array $recipes, ?string ...$additionalClasses): string if (\is_bool($recipeValue)) { $recipeValue = $recipeValue ? 'true' : 'false'; } - $recipeClasses = $this->variants[$recipeName][$recipeValue] ?? []; + $recipeClasses = $this->variants[$recipeName][$recipeValue ?? ''] ?? []; $classes = [...$classes, ...(array) $recipeClasses]; } diff --git a/extra/html-extra/Tests/CvaTest.php b/extra/html-extra/Tests/CvaTest.php index 1239c2c8b94..986142bd4ce 100644 --- a/extra/html-extra/Tests/CvaTest.php +++ b/extra/html-extra/Tests/CvaTest.php @@ -49,6 +49,22 @@ public function testApply(): void $this->assertEquals('font-semibold border rounded text-primary text-sm text-red-500', $recipe->apply(['colors' => 'primary', 'sizes' => 'sm'])); } + public function testApplyWithNullRecipeValue(): void + { + $recipe = new Cva('font-semibold', [ + 'colors' => [ + 'primary' => 'text-primary', + ], + 'sizes' => [ + 'sm' => 'text-sm', + ], + ], [], [ + 'sizes' => 'sm', + ]); + + $this->assertSame('font-semibold text-sm', $recipe->apply(['colors' => null, 'sizes' => null])); + } + public function testApplySameRecipesAgain(): void { $createRecipe = static fn () => new Cva("font-semibold border\nrounded border", [