From 9e3b61a97f134bfacaa98ecd8820136d891d5eac Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Tue, 5 May 2026 09:10:02 +0200 Subject: [PATCH 1/4] Add tests for clamp with incorrect bounds --- tests/Support/SupportNumberTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Support/SupportNumberTest.php b/tests/Support/SupportNumberTest.php index 720e4744fbb4..bf9e59ced94f 100644 --- a/tests/Support/SupportNumberTest.php +++ b/tests/Support/SupportNumberTest.php @@ -195,6 +195,10 @@ public function testClamp() $this->assertSame(5, Number::clamp(5, 1, 10)); $this->assertSame(4.5, Number::clamp(4.5, 1, 10)); $this->assertSame(1, Number::clamp(-10, 1, 5)); + // Incorrect bounds always return 'max' + $this->assertSame(1, Number::clamp(-10, 5, 1)); + $this->assertSame(1, Number::clamp(4, 5, 1)); + $this->assertSame(1, Number::clamp(10, 5, 1)); } public function testToHuman() From d24c6a490bf2a15f3afe07345e0323fe47ab6f50 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Sat, 25 Apr 2026 18:27:51 +0200 Subject: [PATCH 2/4] Add PHP 8.6 polyfill to Support --- src/Illuminate/Support/composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Illuminate/Support/composer.json b/src/Illuminate/Support/composer.json index eb8bd0c66b6e..663d3ac76156 100644 --- a/src/Illuminate/Support/composer.json +++ b/src/Illuminate/Support/composer.json @@ -26,6 +26,7 @@ "illuminate/reflection": "^13.0", "nesbot/carbon": "^3.8.4", "symfony/polyfill-php85": "^1.33", + "symfony/polyfill-php86": "^1.36", "voku/portable-ascii": "^2.0.2" }, "replace": { From 089b266053deda3cdfc003a8ddb80e1c2fba97dd Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Sat, 25 Apr 2026 18:28:53 +0200 Subject: [PATCH 3/4] Defer Number::clamp to native PHP function --- src/Illuminate/Support/Number.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Number.php b/src/Illuminate/Support/Number.php index 6ea2430a98a0..0acbe21fcddf 100644 --- a/src/Illuminate/Support/Number.php +++ b/src/Illuminate/Support/Number.php @@ -310,7 +310,7 @@ protected static function summarize(int|float $number, int $precision = 0, ?int */ public static function clamp(int|float $number, int|float $min, int|float $max) { - return min(max($number, $min), $max); + return clamp($number, $min, $max); } /** From abc064133213c535f5792e5ed3651512e2357fc3 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Tue, 5 May 2026 09:17:04 +0200 Subject: [PATCH 4/4] Convert clamp ValueError to deprecation --- src/Illuminate/Support/Number.php | 9 ++++++++- tests/Support/SupportNumberTest.php | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Number.php b/src/Illuminate/Support/Number.php index 0acbe21fcddf..707ae89372b4 100644 --- a/src/Illuminate/Support/Number.php +++ b/src/Illuminate/Support/Number.php @@ -5,6 +5,7 @@ use Illuminate\Support\Traits\Macroable; use NumberFormatter; use RuntimeException; +use ValueError; class Number { @@ -310,7 +311,13 @@ protected static function summarize(int|float $number, int $precision = 0, ?int */ public static function clamp(int|float $number, int|float $min, int|float $max) { - return clamp($number, $min, $max); + try { + return clamp($number, $min, $max); + } catch (ValueError $e) { + trigger_error($e->getMessage(), E_USER_DEPRECATED); + + return $max; + } } /** diff --git a/tests/Support/SupportNumberTest.php b/tests/Support/SupportNumberTest.php index bf9e59ced94f..e7376404e01d 100644 --- a/tests/Support/SupportNumberTest.php +++ b/tests/Support/SupportNumberTest.php @@ -3,6 +3,7 @@ namespace Illuminate\Tests\Support; use Illuminate\Support\Number; +use PHPUnit\Framework\Attributes\IgnoreDeprecations; use PHPUnit\Framework\Attributes\RequiresPhpExtension; use PHPUnit\Framework\TestCase; @@ -195,9 +196,17 @@ public function testClamp() $this->assertSame(5, Number::clamp(5, 1, 10)); $this->assertSame(4.5, Number::clamp(4.5, 1, 10)); $this->assertSame(1, Number::clamp(-10, 1, 5)); + } + + #[IgnoreDeprecations] + public function testClampIncorrectBounds() + { // Incorrect bounds always return 'max' + $this->expectUserDeprecationMessage('clamp(): Argument #2 ($min) must be smaller than or equal to argument #3 ($max)'); $this->assertSame(1, Number::clamp(-10, 5, 1)); + $this->expectUserDeprecationMessage('clamp(): Argument #2 ($min) must be smaller than or equal to argument #3 ($max)'); $this->assertSame(1, Number::clamp(4, 5, 1)); + $this->expectUserDeprecationMessage('clamp(): Argument #2 ($min) must be smaller than or equal to argument #3 ($max)'); $this->assertSame(1, Number::clamp(10, 5, 1)); }