Skip to content

Allow ARRAY_FILTER_USE_VALUE as the mode of array_filter() and narrow its result - #6681

Open
Amoifr wants to merge 2 commits into
phpstan:2.3.xfrom
Amoifr:feature-15372-array-filter-use-value
Open

Amoifr wants to merge 2 commits into
phpstan:2.3.xfrom
Amoifr:feature-15372-array-filter-use-value

Conversation

@Amoifr

@Amoifr Amoifr commented Oct 5, 2026

Copy link
Copy Markdown

Closes phpstan/phpstan#15372

PHP 8.6 adds ARRAY_FILTER_USE_VALUE (0) as an explicit $mode for array_filter(). It is now part of the allowed constants for that parameter. The parameter takes a single value, so combining it with another mode is still reported as argument.bitmaskNotAllowed.

While testing it, I noticed the result was not narrowed with this mode: ArrayFilterFunctionReturnTypeHelper::determineMode() only recognised the values of ARRAY_FILTER_USE_KEY and ARRAY_FILTER_USE_BOTH, so ARRAY_FILTER_USE_VALUE (and a literal 0) gave array<int, int|null> where omitting the mode gives array<int, int>. A value of 0 now maps to the default mode.

The rule test runs with phpVersion: 80600. The type inference test needs the constant at runtime, so it is gated with // lint >= 8.6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array_filter supports a new constant ARRAY_FILTER_USE_VALUE

2 participants