Skip to content

filter_var_array with a mixed argument results in a fatal error #9178

@daniel-calderini

Description

@daniel-calderini

Bug report

Starting with version 1.10.12, the following code snippet creates a fatal error:

function filter(mixed $data): array
{
	return filter_var_array(
		$data,
		[
			'id' => [
				'filter' => FILTER_VALIDATE_INT,
				'flags' => FILTER_REQUIRE_SCALAR,
			],
		
		],
		true,
	);
}

https://phpstan.org/r/432b5663-9303-4742-969b-f4ac0a168e68

Using version 1.10.11 (or lower), or using array type for the $data argument fixes the fatal error:

function filter(array $data): array
{
	return filter_var_array(
		$data,
		[
			'id' => [
				'filter' => FILTER_VALIDATE_INT,
				'flags' => FILTER_REQUIRE_SCALAR,
			],
		
		],
		true,
	);
}

https://phpstan.org/r/4906b331-8a8d-45c3-860b-2d7039afa990

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