Skip to content

Fix array_find return type defaulting to mixed#11848

Open
eyupcanakman wants to merge 3 commits into
vimeo:masterfrom
eyupcanakman:fix/array-find-return-type-11331
Open

Fix array_find return type defaulting to mixed#11848
eyupcanakman wants to merge 3 commits into
vimeo:masterfrom
eyupcanakman:fix/array-find-return-type-11331

Conversation

@eyupcanakman

Copy link
Copy Markdown
Contributor

Fix #11331

array_find (PHP 8.4) had no return type provider, so its callmap entry resolved to mixed. Extend ArrayFilterReturnTypeProvider to also handle array_find: it reuses the existing callback narrowing and returns the matching element type, or null when nothing matches. The other functions are unchanged.

alies-dev and others added 3 commits May 16, 2026 18:39
The two new tests in TypeParseTest added by vimeo#11768 were written against
master/7.x where Closure types render with an `impure-` purity prefix.
On 6.x there is no purity tracking on Closures, so the actual output is
`Closure(...)` rather than `impure-Closure(...)`. The other 10 new tests
from the PR were unaffected and continue to pass.

Fixes Unit Tests failure on 6.x for testThisAsCallableReturnType and
testThisModelVariableNotTreatedAsThis.
On PHP 8.1/8.2 the `Override` attribute is not a built-in class. When
psalm scans a vendor file using `#[\Override]` (e.g. amphp/socket's
UnlimitedSocketPool), Scanner::fileExistsForClassLike falls back to
`new ReflectionClass('Override')` which triggers the project autoloader.
The suicidal autoloader then exits, failing the SuicidalAutoloaderTest.

The whitelist already handles the analogous PHP 8.2 case
(AllowDynamicProperties) and other version-gated names. Adding `Override`
makes the test pass on PHP 8.1/8.2 again.

Note: this is a test-fixture workaround. A deeper fix would be to teach
Scanner::fileExistsForClassLike to skip ReflectionClass for known
version-gated PHP attribute names; that should be tracked separately.
@eyupcanakman eyupcanakman force-pushed the fix/array-find-return-type-11331 branch from 02ae2fb to 0521730 Compare May 16, 2026 15:47
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.

2 participants