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
ClassStatementsGatherer gathers all 2-element arrays into methodCalls, triggering class reflection in UnusedPrivateMethodRule #15494
In ClassStatementsGatherer, any 2-element array expression is unconditionally collected into $this->methodCalls as a candidate callable:
if ($itemCount === 2) {
$this->methodCalls[] = $node;
}
When the enclosing class declares at least one private method, UnusedPrivateMethodRule iterates through all collected methodCalls and calls $arrayType->isCallable() on each one.
For 2-element data arrays whose first item is a class name (e.g. [BigContainer::class, 'packstation'] or string pairs), ConstantArrayType::isCallable() triggers reflection on that target class. However, private methods of the current class can only be called on $this, self, static, or the current class name itself. Collecting unrelated 2-element data arrays causes unnecessary class reflection.
<?phpnamespaceApp;
class BigContainer
{
}
class Service
{
privatefunctionunusedMethod(): void
{
}
publicfunctionprocess(string$item): bool
{
$modes = [BigContainer::class, 'packstation'];
returnin_array($item, $modes, true);
}
}
Expected output
Two-element arrays whose first item cannot refer to the current class should not be gathered into ClassStatementsGatherer::$methodCalls, avoiding unnecessary class reflection during unused private method analysis.
Activity
mergeable commentedon Oct 17, 2026
This bug report is missing a link to reproduction at phpstan.org/try.
It will most likely be closed after manual review.
staabm commentedon Oct 17, 2026
Please add a phpstan.org/try example. I guess you have expectations regarding missing errors or false positives?
if the root problem of your issue is efficiency, you should provide a reproducer which is inefficient and is improved by your fixes
ondrejmirtes commentedon Oct 24, 2026
Why does reflecting unrelated classes in this case bother you?