Skip to content

Allow core numeric overloads in math and comparison operations #310

@Firehed

Description

@Firehed

Following the completion of phpstan/phpstan#14288, I think it would make sense for the strict rules to permit the various math-related operations when the types will work as expected.

Supported in core:

BCMath: + - * / % ** <=> == > >= < <= Since 2024 so 8.4? (https://wiki.php.net/rfc/support_object_type_in_bcmath)

GMP: Above plus << >> . | & ^ xor ~ ! Since 5.6 (https://wiki.php.net/rfc/operator_overloading_gmp)

I think the case for bitwise where it's supported is somewhat dubious even where supported, but the stuff allowed with BCMath objects should't violate any "principles of least surprise" when operating on combinations of int, float, GMP, and BCMath types, though not having BCMath on one side and GMP on the other, so I think they should not get flagged by the strict rules extension.

I can try to take this on if folks are OK with it; though it seemed a bit ambiguous when working on the supporting type resolution pieces in phpstan-src.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions