Skip to content

[13.x] Fix Number::trim() throwing TypeError when passed INF or NAN#59544

Open
romdh4ne wants to merge 1 commit intolaravel:13.xfrom
romdh4ne:fix-number-trim-non-finite
Open

[13.x] Fix Number::trim() throwing TypeError when passed INF or NAN#59544
romdh4ne wants to merge 1 commit intolaravel:13.xfrom
romdh4ne:fix-number-trim-non-finite

Conversation

@romdh4ne
Copy link
Copy Markdown

@romdh4ne romdh4ne commented Apr 5, 2026

Number::trim() uses json_decode(json_encode($number)) internally.
However, json_encode(INF) and json_encode(NAN) return false in PHP
since these are not valid JSON values. json_decode(false) then returns
null, which violates the declared return type int|float and throws
a Fatal TypeError.

How to reproduce

Number::trim(INF);  // Fatal TypeError: Return value must be of type int|float, null returned
Number::trim(NAN);  // Fatal TypeError: Return value must be of type int|float, null returned

Fix

Guard with is_finite() before encoding. Non-finite values are returned
as-is since there are no trailing zeros to trim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant