Skip to content

[CodingStyle] Require object in ClosureFromCallableToFirstClassCallableRector - #9045

Merged
TomasVotruba merged 1 commit into
mainfrom
closure-from-callable-require-object
Nov 23, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
closure-from-callable-require-object

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

ClosureFromCallableToFirstClassCallableRector turned Closure::fromCallable([$obj, 'method']) into $obj->method(...) with no check on $obj. When $obj is a class name string, the callable is static and the result breaks:

function make(string $obj)
{
    // before: returns a closure of Foo::method() for make('Foo')
    return Closure::fromCallable([$obj, 'method']);
}

function make(string $obj)
{
    // after: Error: Call to a member function method() on string
    return $obj->method(...);
}

Fix - convert a variable first item only when its type is an object, otherwise skip. Existing fixture now types $obj as an object, new skip fixture covers string-typed and untyped $obj.

@TomasVotruba
TomasVotruba merged commit 79e289f into main Nov 23, 2026
51 checks passed
@TomasVotruba
TomasVotruba deleted the closure-from-callable-require-object branch November 23, 2026 22:32
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