Skip to content

Commit d3a9a3d

Browse files
authored
Fix phpstan/phpstan#14384: Result of function_exists() can't be "cached" (#5303)
1 parent c381cc0 commit d3a9a3d

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/Analyser/ExprHandler/AssignHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PhpParser\Node\Expr\Assign;
1111
use PhpParser\Node\Expr\AssignRef;
1212
use PhpParser\Node\Expr\ConstFetch;
13+
use PhpParser\Node\Expr\FuncCall;
1314
use PhpParser\Node\Expr\List_;
1415
use PhpParser\Node\Expr\MethodCall;
1516
use PhpParser\Node\Expr\PropertyFetch;
@@ -863,6 +864,7 @@ private function processSureTypesForConditionalExpressionsAfterAssign(Scope $sco
863864
} elseif (
864865
!$expr instanceof PropertyFetch
865866
&& !$expr instanceof ArrayDimFetch
867+
&& !$expr instanceof FuncCall
866868
) {
867869
continue;
868870
}
@@ -901,6 +903,7 @@ private function processSureNotTypesForConditionalExpressionsAfterAssign(Scope $
901903
} elseif (
902904
!$expr instanceof PropertyFetch
903905
&& !$expr instanceof ArrayDimFetch
906+
&& !$expr instanceof FuncCall
904907
) {
905908
continue;
906909
}

tests/PHPStan/Rules/Functions/CallToNonExistentFunctionRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,9 @@ public function testRememberFunctionExistsFromConstructor(): void
254254
]);
255255
}
256256

257+
public function testBug14384(): void
258+
{
259+
$this->analyse([__DIR__ . '/data/bug-14384.php'], []);
260+
}
261+
257262
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug14384;
4+
5+
$canCall = function_exists('some_totally_nonexistent_function_14384');
6+
7+
if ($canCall) {
8+
some_totally_nonexistent_function_14384();
9+
}

0 commit comments

Comments
 (0)