Skip to content

Numbers starting with 0 fail validation using FILTER_VALIDATE_INT #9378

@ollieread

Description

@ollieread

Description

The following code:

<?php

declare(strict_types=1);

var_dump(filter_var('00', FILTER_VALIDATE_INT));
var_dump(filter_var('0', FILTER_VALIDATE_INT));
var_dump(filter_var('01', FILTER_VALIDATE_INT));
var_dump(filter_var('1', FILTER_VALIDATE_INT));

Resulted in this output:

bool(false)
int(0)
bool(false)
int(1)

But I expected this output instead:

int(0)
int(0)
int(1)
int(1)

PHP Version

PHP 8.1.4

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions