Skip to content

PHPStan deny use validation the function argument if union types are expected as argument #2538

@peter-gribanov

Description

@peter-gribanov

Support question

https://phpstan.org/r/71fa67e2-1d56-48a9-9cc3-35fb7cf110b1

PHP does not support union data types in an argument. Valid data types are described in the annotations, but in reality, the mixed type data comes into the method. Therefore, it is necessary to check in the method code which data type actually came and if an invalid data type came, then throw exception.

I know only one way around this problem is to explicitly indicate in the annotations the data type as a mixed or object if we use argument type hinting.

Is there any other solution to this problem?

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