Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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',
Expand Down Expand Up @@ -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(
Expand All @@ -598,7 +603,7 @@ public function afterOpenSslCall(string $openSslFunctionName): self
$this->getFunction(),
$this->getNamespace(),
$expressionTypes,
$this->nativeExpressionTypes,
$nativeExpressionTypes,
$this->conditionalExpressions,
$this->inClosureBindScopeClasses,
$this->anonymousFunctionReflection,
Expand Down
4 changes: 4 additions & 0 deletions tests/PHPStan/Analyser/nsrt/bug-7106.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
namespace Bug7106;

use function PHPStan\Testing\assertType;
use function PHPStan\Testing\assertNativeType;
use function openssl_error_string;

Class Example
{
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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-11484.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace Bug11484;

class HelloWorld
{
public function sayHello(): void
{
if (filesize("file.txt") > 100) {
file_put_contents("file.txt", str_repeat('aaaaaaa', rand(1,100)));
clearstatcache();
if (filesize("file.txt") > 50) {

}
}

}
}
Loading