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
I must confirm this still happens, I, very unwillingly, bypassed it by removing the |null from the type, which shouldn't be needed. and it's inconsistent with the App class definition.
The App class defines @template TContainerInterface of (ContainerInterface|null),
now normally @param App<ContainerInterface|null> $app works, but not when you call function within the same class that has the same annotation as input:
<?php
class MyClass {
/**
* @param App<ContainerInterface|null> $app
*/
public function registerSomething(App $app): void
{
$this->doRegister(
app: $app,
target: 'something',
);
}
/**
* @param App<ContainerInterface|null> $app
*/
private function doRegister(App $app, string $target): void
{
$app->magic($target);
}
}
I even tried to define a union type TContainerInterface on the class level as the App class does it and use App<TContainerInterface> - no still the same problem on the line calling ->doRegister(...:
Parameter $app of method MyClass<TContainerInterface of Psr\Container\ContainerInterface|null>::doRegister() expects
App<Psr\Container\ContainerInterface|null>, App<Psr\Container\ContainerInterface|null> given.
Note that I have the latest phpstan as of now - "2.1.14".
Activity
tamiroh commentedon Sep 3, 2024
Having attempted somewhat, it seems that setting
featureToggles.newRuleLevelHelpertofalseworks around this problem for now 👀ondrejmirtes commentedon Sep 3, 2024
@tamiroh That's not a solution. This option will go away in 2.0 and everybody will get the same (new) behaviour.
tamiroh commentedon Sep 3, 2024
@ondrejmirtes Yes, you are right. This is just a temporary work-around 😓. So I was just starting to think about how to fix it.
realjjaveweb commentedon May 5, 2025
I must confirm this still happens, I, very unwillingly, bypassed it by removing the
|nullfrom the type, which shouldn't be needed. and it's inconsistent with the App class definition.The App class defines
@template TContainerInterface of (ContainerInterface|null),now normally
@param App<ContainerInterface|null> $appworks, but not when you call function within the same class that has the same annotation as input:I even tried to define a union type TContainerInterface on the class level as the App class does it and use
App<TContainerInterface>- no still the same problem on the line calling->doRegister(...:Note that I have the latest phpstan as of now - "2.1.14".
I mean the types are FQNs and EXACTLY the same.
VincentLanglet commentedon Aug 2, 2025
This is the same issue than #9096 (comment)
phpstan-bot commentedon Sep 10, 2026
Closed via merging phpstan/phpstan-src#6392
github-actions commentedon Oct 12, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.