diff --git a/src/Reflection/Annotations/AnnotationMethodReflection.php b/src/Reflection/Annotations/AnnotationMethodReflection.php index b93316270c6..ca0484d916e 100644 --- a/src/Reflection/Annotations/AnnotationMethodReflection.php +++ b/src/Reflection/Annotations/AnnotationMethodReflection.php @@ -109,6 +109,13 @@ public function getThrowType(): ?Type public function hasSideEffects(): TrinaryLogic { + if ( + strtolower($this->getName()) !== '__construct' + && $this->returnType->isVoid()->yes() + ) { + return TrinaryLogic::createYes(); + } + return TrinaryLogic::createMaybe(); } diff --git a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php index d5f15687065..4f8b9cbfc26 100644 --- a/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php @@ -613,4 +613,10 @@ public function testPhpUnitIntegration(): void $this->analyse([__DIR__ . '/../../Analyser/data/phpunit-integration.php'], []); } + public function testBug8586(): void + { + $this->checkAlwaysTrueStrictComparison = true; + $this->analyse([__DIR__ . '/data/bug-8586.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-8586.php b/tests/PHPStan/Rules/Comparison/data/bug-8586.php new file mode 100644 index 00000000000..2b004a9f569 --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-8586.php @@ -0,0 +1,38 @@ +getString() === null); + $em->refreshFromAnnotation($foo); + \assert($foo->getString() !== null); + } + + public function sayHello2(Foo $foo, EntityManager $em): void + { + \assert($foo->getString() === null); + $em->refresh($foo); + \assert($foo->getString() !== null); + } +}