Skip to content

[CodingStyle] Skip closure with rebound $this on ArrowFunction/ClosureDelegatingCallToFirstClassCallableRector - #8931

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-9964-rebound-closure
Nov 13, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
fix-9964-rebound-closure

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9964

(fn ($id) => $this->addDefinition($id))->call($container, ...) rebinds $this to $container. The first-class callable $this->addDefinition(...) binds $this at creation time, so the rewrite calls the method on the wrong object (or fatals).

  • new ReboundClosureNodeVisitor marks a closure/arrow fn that is the direct receiver of ->call() / ->bindTo()
  • ArrowFunctionAndClosureFirstClassCallableGuard skips marked nodes, so both arrow fn and closure rules are covered
  • Closure::bind(fn ..., $obj) is already skipped via HAS_CLOSURE_WITH_VARIADIC_ARGS, covered by fixture as regression

… on ArrowFunction/ClosureDelegatingCallToFirstClassCallableRector

Fixes rectorphp/rector#9964
@TomasVotruba
TomasVotruba merged commit cc2f664 into main Nov 13, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the fix-9964-rebound-closure branch November 13, 2026 21:46
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.

ArrowFunctionDelegatingCallToFirstClassCallableRector breaks code that relies on $this rebinding via Closure::call()

1 participant