You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PHP: a method called on a freshly constructed object, (new Foo())->bar(), ignores the file's use import when several classes share the short name #3244
In PHP, a call on a freshly constructed object, (new SettingClient())->getSet(1), is not linked to the class the file imports when several classes in different namespaces share that short name. The same pattern was fixed for JavaScript/TypeScript in #1945; PHP doesn't seem to have an equivalent.
So on 1.6.2 every call goes to whichever same-named class was indexed first, and the (new Foo())->bar() call in FooApi gets no edge at all.
On main
The Unreleased changelog entry "In PHP, a call on a variable now reaches the method its class really has … through the file's namespace and use imports" looks like it covers BarApi and BazApi (I couldn't build main locally to confirm). But I couldn't find a PHP counterpart for the parenthesized new receiver: in src/extraction/tree-sitter.ts the PHP member_call_expression branch special-cases a scoped_call_expression receiver (Cls::for()->m(), #608) but not an object_creation_expression / parenthesized_expression one, and none of the __tests__/php-*.test.ts files use (new X())->m().
Why it matters
In a real Laravel 7 codebase (~11k first-party PHP files) about 28% of files share a short name with another file — per-module client wrappers like TeamClient exist in 30+ namespaces — and (new XxxClient())->method() is the dominant call style. On 1.6.2, callers/impact for one copy returned 0 callers while grep found 8+, and attributed callers of the other copies to the wrong class.
Expected
Resolve the class in (new Foo())->bar() (and (new Foo)->bar(), (new Foo($x))->bar()) through the file's namespace and use imports, as for a typed variable, and link bar to that class's own or inherited method.
Related: #2975 (same short-name issue for Laravel route → controller).
Activity