Skip to content

Enhance FILTER_VALIDATE_INT option in filter_var #7608

@takeokunn

Description

@takeokunn

Feature request

https://phpstan.org/r/cd41cbe6-b757-4d79-b345-cbc660f00d1e

assertType("1", intval("1"));
assertType("100", intval("100"));
assertType("0", filter_var("0", FILTER_VALIDATE_INT));
assertType("1", filter_var("1", FILTER_VALIDATE_INT));
assertType("100", filter_var("100", FILTER_VALIDATE_INT));
assertType("false", filter_var("abc", FILTER_VALIDATE_INT));
assertType("null", filter_var("abc", FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE));

// for octal
assertType("8", filter_var("0o10", FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_OCTAL));

// for hex
assertType("16", filter_var("0x10", FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_HEX));

intval can cast ConstantString like1 , but filter_var cannot.

Did PHPStan help you today? Did it make you happy in any way?

PHP is now properly typed and easier to develop with Emacs.

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