diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 398e309c10..a0038dbe0c 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -1913,7 +1913,7 @@ function (MutatingScope $scope) use ($expr, $nodeCallback, $context): Expression $scope = $scope->afterExtractCall(); } - if (isset($functionReflection) && $functionReflection->getName() === 'clearstatcache') { + if (isset($functionReflection) && ($functionReflection->getName() === 'clearstatcache' || $functionReflection->getName() === 'unlink')) { $scope = $scope->afterClearstatcacheCall(); } diff --git a/tests/PHPStan/Analyser/data/clear-stat-cache.php b/tests/PHPStan/Analyser/data/clear-stat-cache.php index bf565eedf2..f7a4d17269 100644 --- a/tests/PHPStan/Analyser/data/clear-stat-cache.php +++ b/tests/PHPStan/Analyser/data/clear-stat-cache.php @@ -52,3 +52,11 @@ function (string $a, string $b, bool $c): string { assertType('true', $c); } }; + +function (): void { + if (file_exists('foo')) { + assertType('true', file_exists('foo')); + unlink('foo'); + assertType('bool', file_exists('foo')); + } +};