Skip to content

[TypeDeclaration] Skip maybe object items on AddArrowFunctionParamArrayWhereDimFetchRector - #9073

Merged
TomasVotruba merged 1 commit into
rectorphp:mainfrom
odolbeau:fix/arrow-fn-array-param-mixed-items
Nov 26, 2026
Merged

TomasVotruba merged 1 commit into
rectorphp:mainfrom
odolbeau:fix/arrow-fn-array-param-mixed-items

Conversation

@odolbeau

Copy link
Copy Markdown
Contributor

AddArrowFunctionParamArrayWhereDimFetchRector skips closures only when the iterated items are always objects (#7113). When the items are a union that includes an ArrayAccess object, it still adds an array type, which causes a TypeError at runtime:

/** @param array<int, array{id: int}|\ArrayAccess<string, int>> $items */
public function run(array $items)
{
    return array_filter($items, fn ($item) => $item['id'] ?? null);
    // became: fn (array $item) => ...
}

Fix: skip when the item type may be an object. Items of type mixed are still typed as before (see handle_usort.php.inc).

Added fixture: skip_maybe_array_access_item.php.inc.

…ayWhereDimFetchRector

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TomasVotruba
TomasVotruba merged commit 310fbc6 into rectorphp:main Nov 26, 2026
51 checks passed
@TomasVotruba

Copy link
Copy Markdown
Member

Thank you!

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants