Defer by-ref closure scope modifications after all args are processed by ondrejmirtes · Pull Request #4865 · phpstan/phpstan-src

@ondrejmirtes @claude

processClosureNode returned a scope with by-ref captured variable
modifications already applied. In processArgs, this polluted the
scope used for evaluating subsequent arguments - but closures are
not called during argument evaluation, so by-ref changes cannot
have taken effect yet.

The fix separates the by-ref data (closureResultScope, byRefUses)
from the returned scope in ProcessClosureResult and lets callers
decide when to apply it. The standalone closure call site applies
immediately, while processArgs defers it until after all arguments
are processed - same pattern as the existing deferral of
processImmediatelyCalledCallable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

phpstan-bot pushed a commit that referenced this pull request

Feb 12, 2026

@ondrejmirtes @phpstan-bot