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
InaccessibleMethod on a trait method made private by a use adaptation when the parent has __call() #14020
When a class makes a public trait method private with a use adaptation (product as private) and its parent declares __call(), a call from outside the class should go through __call(), because PHP calls __call() for an inaccessible method. Psalm reports InaccessibleMethod instead.
A private method declared directly in Child goes through the magic-method path, as expected (https://psalm.dev/r/dd8cdcf5cd: UndefinedMagicMethod, no InaccessibleMethod).
With /** @method int product() */ on ParentClass (https://psalm.dev/r/8202a5e697), the trait case still reports InaccessibleMethod, and the result is inferred as string, the trait method's return type, instead of int. With a private method declared in Child, there is no InaccessibleMethod and the result is int.
Expected: the privately aliased trait method behaves like a private method declared in the class. There's no InaccessibleMethod, the call resolves through __call(), and $a is int with the @method annotation.
Psalm output (using commit f349d3a):
ERROR: InaccessibleMethod - 21:19 - Cannot access private method Child::product
INFO: Trace - 22:23 - $a: int
INFO: UnusedVariable - 21:1 - $a is never referenced or the value is not used
ERROR: InvalidReturnType - 10:32 - The declared return type 'int' for RealTrait::product is incorrect, got ''Screen''
The same cause shows up in the other direction: a private trait method made protected by an adaptation in a parent class is treated as not visible from the child, so a __call() in the grandparent takes the call over.
MethodAnalyzer::isMethodVisible() reads the visibility of the declaring method (private in the trait, public in the snippet above) and ignores the trait_visibility_map of the class where the method appears, which MethodVisibilityAnalyzer does take into account.
Psalm output (using commit 30edada):
ERROR: UndefinedMagicMethod - 16:21 - Magic method R3::product does not exist
INFO: MixedAssignment - 16:9 - Unable to determine the type that $a is being assigned to
INFO: Trace - 17:31 - $a: mixed
INFO: MixedReturnStatement - 18:16 - Could not infer a return type
Psalm output (using commit 30edada):
INFO: Trace - 18:31 - $a: int
ERROR: InvalidReturnStatement - 19:16 - The inferred type 'int' does not match the declared return type 'string' for R3::t
ERROR: InvalidReturnType - 16:26 - The declared return type 'string' for R3::t is incorrect, got 'int'
https://psalm.dev/r/01a6767b83
<?phptrait Impl {
privatefunctionimpl(): string { return""; }
}
class P {
}
classR2extends P {
use Impl { impl asprotected product; }
}
finalclassR3extendsR2 {
publicfunctiont(): string {
$a = $this->product();
/** @psalm-trace $a */;
return$a;
}
}
Activity
psalm-github-bot commentedon Nov 16, 2026
I found these snippets:
https://psalm.dev/r/f33e45893a
https://psalm.dev/r/dd8cdcf5cd
https://psalm.dev/r/8202a5e697
orklah commentedon Nov 16, 2026
The same cause shows up in the other direction: a private trait method made protected by an adaptation in a parent class is treated as not visible from the child, so a
__call()in the grandparent takes the call over.https://psalm.dev/r/62b0c8bce2
PHP runs
Impl::impl()here, so$ashould bestringwith no issue. With/** @method int product() */onP(https://psalm.dev/r/1a31cc0972),$aisint. Without__call()onP(https://psalm.dev/r/01a6767b83),$aisstring, as expected.MethodAnalyzer::isMethodVisible()reads the visibility of the declaring method (privatein the trait,publicin the snippet above) and ignores thetrait_visibility_mapof the class where the method appears, whichMethodVisibilityAnalyzerdoes take into account.psalm-github-bot commentedon Nov 16, 2026
I found these snippets:
https://psalm.dev/r/62b0c8bce2
https://psalm.dev/r/1a31cc0972
https://psalm.dev/r/01a6767b83
fix(visibility): a use adaptation changes the visibility a method cal…