diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 1e323aff2c..3f36685a2e 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -477,6 +477,7 @@ public function afterExtractCall(): self public function afterClearstatcacheCall(): self { $expressionTypes = $this->expressionTypes; + $nativeExpressionTypes = $this->nativeExpressionTypes; foreach (array_keys($expressionTypes) as $exprString) { // list from https://www.php.net/manual/en/function.clearstatcache.php @@ -507,16 +508,18 @@ public function afterClearstatcacheCall(): self } unset($expressionTypes[$exprString]); + unset($nativeExpressionTypes[$exprString]); continue 2; } } + return $this->scopeFactory->create( $this->context, $this->isDeclareStrictTypes(), $this->getFunction(), $this->getNamespace(), $expressionTypes, - $this->nativeExpressionTypes, + $nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClasses, $this->anonymousFunctionReflection, @@ -533,6 +536,7 @@ public function afterClearstatcacheCall(): self public function afterOpenSslCall(string $openSslFunctionName): self { $expressionTypes = $this->expressionTypes; + $nativeExpressionTypes = $this->nativeExpressionTypes; if (in_array($openSslFunctionName, [ 'openssl_cipher_iv_length', @@ -590,6 +594,7 @@ public function afterOpenSslCall(string $openSslFunctionName): self 'openssl_x509_verify', ], true)) { unset($expressionTypes['\openssl_error_string()']); + unset($nativeExpressionTypes['\openssl_error_string()']); } return $this->scopeFactory->create( @@ -598,7 +603,7 @@ public function afterOpenSslCall(string $openSslFunctionName): self $this->getFunction(), $this->getNamespace(), $expressionTypes, - $this->nativeExpressionTypes, + $nativeExpressionTypes, $this->conditionalExpressions, $this->inClosureBindScopeClasses, $this->anonymousFunctionReflection, diff --git a/tests/PHPStan/Analyser/nsrt/bug-7106.php b/tests/PHPStan/Analyser/nsrt/bug-7106.php index 50e6c0e86f..915965c236 100644 --- a/tests/PHPStan/Analyser/nsrt/bug-7106.php +++ b/tests/PHPStan/Analyser/nsrt/bug-7106.php @@ -5,6 +5,7 @@ namespace Bug7106; use function PHPStan\Testing\assertType; +use function PHPStan\Testing\assertNativeType; use function openssl_error_string; Class Example @@ -12,11 +13,14 @@ public function openSslError(string $signature): string { assertType('string|false', openssl_error_string()); + assertNativeType('string|false', openssl_error_string()); if (false === \openssl_error_string()) { assertType('false', openssl_error_string()); + assertNativeType('false', openssl_error_string()); openssl_sign('1', $signature, ''); assertType('string|false', openssl_error_string()); + assertNativeType('string|false', openssl_error_string()); } } } diff --git a/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php index a6981ba1b9..90bd8673de 100644 --- a/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php @@ -233,6 +233,12 @@ public function testBug6467(): void $this->analyse([__DIR__ . '/data/bug-6467.php'], []); } + public function testBug11484(): void + { + $this->treatPhpDocTypesAsCertain = false; + $this->analyse([__DIR__ . '/data/bug-11484.php'], []); + } + public function testBug6642(): void { $this->treatPhpDocTypesAsCertain = true; diff --git a/tests/PHPStan/Rules/Comparison/data/bug-11484.php b/tests/PHPStan/Rules/Comparison/data/bug-11484.php new file mode 100644 index 0000000000..b2ee1bc37d --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-11484.php @@ -0,0 +1,18 @@ + 100) { + file_put_contents("file.txt", str_repeat('aaaaaaa', rand(1,100))); + clearstatcache(); + if (filesize("file.txt") > 50) { + + } + } + + } +}