Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6c44887

Browse files
Invalidate native expression types after clearstatcache call (#4448)
1 parent 3551681 commit 6c44887

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

‎src/Analyser/MutatingScope.php‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ public function afterExtractCall(): self
477477
public function afterClearstatcacheCall(): self
478478
{
479479
$expressionTypes = $this->expressionTypes;
480+
$nativeExpressionTypes = $this->nativeExpressionTypes;
480481
foreach (array_keys($expressionTypes) as $exprString) {
481482
// list from https://www.php.net/manual/en/function.clearstatcache.php
482483

@@ -507,16 +508,18 @@ public function afterClearstatcacheCall(): self
507508
}
508509

509510
unset($expressionTypes[$exprString]);
511+
unset($nativeExpressionTypes[$exprString]);
510512
continue 2;
511513
}
512514
}
515+
513516
return $this->scopeFactory->create(
514517
$this->context,
515518
$this->isDeclareStrictTypes(),
516519
$this->getFunction(),
517520
$this->getNamespace(),
518521
$expressionTypes,
519-
$this->nativeExpressionTypes,
522+
$nativeExpressionTypes,
520523
$this->conditionalExpressions,
521524
$this->inClosureBindScopeClasses,
522525
$this->anonymousFunctionReflection,
@@ -533,6 +536,7 @@ public function afterClearstatcacheCall(): self
533536
public function afterOpenSslCall(string $openSslFunctionName): self
534537
{
535538
$expressionTypes = $this->expressionTypes;
539+
$nativeExpressionTypes = $this->nativeExpressionTypes;
536540

537541
if (in_array($openSslFunctionName, [
538542
'openssl_cipher_iv_length',
@@ -590,6 +594,7 @@ public function afterOpenSslCall(string $openSslFunctionName): self
590594
'openssl_x509_verify',
591595
], true)) {
592596
unset($expressionTypes['\openssl_error_string()']);
597+
unset($nativeExpressionTypes['\openssl_error_string()']);
593598
}
594599

595600
return $this->scopeFactory->create(
@@ -598,7 +603,7 @@ public function afterOpenSslCall(string $openSslFunctionName): self
598603
$this->getFunction(),
599604
$this->getNamespace(),
600605
$expressionTypes,
601-
$this->nativeExpressionTypes,
606+
$nativeExpressionTypes,
602607
$this->conditionalExpressions,
603608
$this->inClosureBindScopeClasses,
604609
$this->anonymousFunctionReflection,

‎tests/PHPStan/Analyser/nsrt/bug-7106.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@
55
namespace Bug7106;
66

77
use function PHPStan\Testing\assertType;
8+
use function PHPStan\Testing\assertNativeType;
89
use function openssl_error_string;
910

1011
Class Example
1112
{
1213
public function openSslError(string $signature): string
1314
{
1415
assertType('string|false', openssl_error_string());
16+
assertNativeType('string|false', openssl_error_string());
1517

1618
if (false === \openssl_error_string()) {
1719
assertType('false', openssl_error_string());
20+
assertNativeType('false', openssl_error_string());
1821
openssl_sign('1', $signature, '');
1922
assertType('string|false', openssl_error_string());
23+
assertNativeType('string|false', openssl_error_string());
2024
}
2125
}
2226
}

‎tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ public function testBug6467(): void
233233
$this->analyse([__DIR__ . '/data/bug-6467.php'], []);
234234
}
235235

236+
public function testBug11484(): void
237+
{
238+
$this->treatPhpDocTypesAsCertain = false;
239+
$this->analyse([__DIR__ . '/data/bug-11484.php'], []);
240+
}
241+
236242
public function testBug6642(): void
237243
{
238244
$this->treatPhpDocTypesAsCertain = true;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug11484;
4+
5+
class HelloWorld
6+
{
7+
public function sayHello(): void
8+
{
9+
if (filesize("file.txt") > 100) {
10+
file_put_contents("file.txt", str_repeat('aaaaaaa', rand(1,100)));
11+
clearstatcache();
12+
if (filesize("file.txt") > 50) {
13+
14+
}
15+
}
16+
17+
}
18+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /