diff --git a/src/Analyser/DirectScopeFactory.php b/src/Analyser/DirectScopeFactory.php index e4646f9900..65362ca98a 100644 --- a/src/Analyser/DirectScopeFactory.php +++ b/src/Analyser/DirectScopeFactory.php @@ -23,6 +23,9 @@ class DirectScopeFactory implements ScopeFactory { + /** + * @param class-string $scopeClass + */ public function __construct( private string $scopeClass, private ReflectionProvider $reflectionProvider, diff --git a/src/Analyser/LazyScopeFactory.php b/src/Analyser/LazyScopeFactory.php index 99671960e1..7ba788c24d 100644 --- a/src/Analyser/LazyScopeFactory.php +++ b/src/Analyser/LazyScopeFactory.php @@ -24,6 +24,9 @@ class LazyScopeFactory implements ScopeFactory private bool $explicitMixedInUnknownGenericNew; + /** + * @param class-string $scopeClass + */ public function __construct( private string $scopeClass, private Container $container, diff --git a/stubs/core.stub b/stubs/core.stub index d04a95ddd1..94e8027efc 100644 --- a/stubs/core.stub +++ b/stubs/core.stub @@ -1,7 +1,7 @@ analyse([__DIR__ . '/data/bug-7017.php'], $errors); } + public function testBug4371(): void + { + $errors = [ + [ + 'Parameter #1 $object_or_class of function is_a expects object, string given.', + 14, + ], + [ + 'Parameter #1 $object_or_class of function is_a expects object, string given.', + 22, + ], + ]; + + if (PHP_VERSION_ID < 80000) { + // php 7.x had different parameter names + $errors = [ + [ + 'Parameter #1 $object_or_string of function is_a expects object, string given.', + 14, + ], + [ + 'Parameter #1 $object_or_string of function is_a expects object, string given.', + 22, + ], + ]; + } + + $this->analyse([__DIR__ . '/data/bug-4371.php'], $errors); + } + } diff --git a/tests/PHPStan/Rules/Functions/data/bug-4371.php b/tests/PHPStan/Rules/Functions/data/bug-4371.php new file mode 100644 index 0000000000..865a5ab606 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-4371.php @@ -0,0 +1,34 @@ +