Skip to content

validateInteger incorrectly passes bool true #56407

@jlt-jacksondawson

Description

@jlt-jacksondawson

Laravel Version

current 12.x

PHP Version

all

Database Driver & Version

No response

Description

I found #28685 which was closed, attributing the problem to a PHP "bug."

Per PHP's documentation of filter_var():

filter_var() converts scalar values to strings before filtering

Because true is being converted to "1", it then passes as an int-ish value.

This isn't technically a PHP bug. it's a type coercion quirk/gotcha that should be accounted for.

The workaround suggested in the other issue should be the permanent fix:

return is_numeric($value) && filter_var($value, FILTER_VALIDATE_INT);

Steps To Reproduce

Pass Boolean true to a field validation with the integer rule set.

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