Skip to content

[Php81] Skip array returned as array type in ArrayToFirstClassCallableRector - #9035

Merged
TomasVotruba merged 1 commit into
mainfrom
array-to-first-class-callable-skip-array-return
Nov 23, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
array-to-first-class-callable-skip-array-return

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

ArrayToFirstClassCallableRector converted an array callable returned from a function declared to return array, which then returns a Closure - a TypeError at runtime:

 public function provideListenerPriority(): array
 {
-    return [SomeExternalObject::class, 'sleepStatic'];
+    return SomeExternalObject::sleepStatic(...);
 }

The rule already skipped arrays passed to an array param, but not returns.

Fix: ContextNodeVisitor now marks an array returned from a function, method, closure or arrow function whose native return type is array/iterable (nullable, or a union with them and no callable/Closure/mixed/object), and the rule skips it. Untyped returns, nested closures inside such a method, and array|callable returns still convert.

The static_with_other_object_const_fetch fixture encoded the bug, so it is now skip_static_with_other_object_const_fetch_returned_as_array; the static external call conversion is covered by return_in_untyped_method.

@TomasVotruba
TomasVotruba merged commit 30cd83a into main Nov 23, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the array-to-first-class-callable-skip-array-return branch November 23, 2026 22:26
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.

1 participant