Skip to content

allowComparingOnlyComparableTypes: add support for BcMath\Number#360

Merged
janedbal merged 2 commits into
shipmonk-rnd:masterfrom
whataboutpereira:master
May 18, 2026
Merged

allowComparingOnlyComparableTypes: add support for BcMath\Number#360
janedbal merged 2 commits into
shipmonk-rnd:masterfrom
whataboutpereira:master

Conversation

@whataboutpereira
Copy link
Copy Markdown
Contributor

Allow BcMath\Number to be compared with integers and itself.

@janedbal
Copy link
Copy Markdown
Member

We need to be very careful about the allow/deny decisions here.

Allow BcMath\Number to be compared with integers and itself.

What makes you decide this way? Why not allow comparing to itself only? And if int is allowed, why not float?

@whataboutpereira
Copy link
Copy Markdown
Contributor Author

We need to be very careful about the allow/deny decisions here.

Allow BcMath\Number to be compared with integers and itself.

What makes you decide this way? Why not allow comparing to itself only? And if int is allowed, why not float?

new BcMath\Number('1.35') > 1.35;

BcMath\Number doesn't work with floats and gives a deprecation notice (it does work with numeric strings though).

Same as is mentioned here #320

Deprecated: Implicit conversion from float 1.35 to int loses precision

Comment thread src/Rule/AllowComparingOnlyComparableTypesRule.php
Comment thread tests/Rule/data/AllowComparingOnlyComparableTypesRule/code.php
@whataboutpereira whataboutpereira force-pushed the master branch 2 times, most recently from 71c031b to 8deb5dd Compare May 14, 2026 09:53
@whataboutpereira
Copy link
Copy Markdown
Contributor Author

Let me know if you want allowNumericString for this as well:

5a872de

@janedbal
Copy link
Copy Markdown
Member

Let me know if you want allowNumericString for this as well:

It adds complexity and some ambiguity where exactly those numeric strings would get allowed.

So not yet. Thx

@whataboutpereira whataboutpereira requested a review from janedbal May 14, 2026 12:47
Comment thread tests/Rule/data/AllowComparingOnlyComparableTypesRule/code.php
@whataboutpereira whataboutpereira requested a review from janedbal May 14, 2026 13:53
@janedbal janedbal merged commit 5ff13f6 into shipmonk-rnd:master May 18, 2026
30 checks passed
@whataboutpereira
Copy link
Copy Markdown
Contributor Author

Cheers!

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.

2 participants