Skip to content

Commit 55c63e4

Browse files
phpstan-botclaude
andcommitted
Revert AssignHandler changes for bug #14473
The fix for the false positive logicalOr.leftAlwaysTrue on repeated builtin function calls does not require code changes to AssignHandler. The root cause is that TypeSpecifier already returns empty SpecifiedTypes for functions with hasSideEffects()->yes() (TypeSpecifier.php line 2246), which prevents conditional expressions from being created in AssignHandler. The proper fix is to mark mysqli_connect in the function metadata, which is done in the next commit. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 38f6006 commit 55c63e4

1 file changed

Lines changed: 2 additions & 25 deletions

File tree

src/Analyser/ExprHandler/AssignHandler.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
use PHPStan\Node\PropertyAssignNode;
4646
use PHPStan\Node\VariableAssignNode;
4747
use PHPStan\Php\PhpVersion;
48-
use PHPStan\Reflection\ReflectionProvider;
4948
use PHPStan\ShouldNotHappenException;
5049
use PHPStan\TrinaryLogic;
5150
use PHPStan\Type\Accessory\AccessoryArrayListType;
@@ -85,7 +84,6 @@ final class AssignHandler implements ExprHandler
8584
public function __construct(
8685
private TypeSpecifier $typeSpecifier,
8786
private PhpVersion $phpVersion,
88-
private ReflectionProvider $reflectionProvider,
8987
)
9088
{
9189
}
@@ -863,13 +861,10 @@ private function processSureTypesForConditionalExpressionsAfterAssign(Scope $sco
863861
if ($expr->name === $variableName) {
864862
continue;
865863
}
866-
} elseif ($expr instanceof FuncCall) {
867-
if ($this->isBuiltinFunctionCallWithPossibleSideEffects($expr, $scope)) {
868-
continue;
869-
}
870864
} elseif (
871865
!$expr instanceof PropertyFetch
872866
&& !$expr instanceof ArrayDimFetch
867+
&& !$expr instanceof FuncCall
873868
) {
874869
continue;
875870
}
@@ -905,13 +900,10 @@ private function processSureNotTypesForConditionalExpressionsAfterAssign(Scope $
905900
if ($expr->name === $variableName) {
906901
continue;
907902
}
908-
} elseif ($expr instanceof FuncCall) {
909-
if ($this->isBuiltinFunctionCallWithPossibleSideEffects($expr, $scope)) {
910-
continue;
911-
}
912903
} elseif (
913904
!$expr instanceof PropertyFetch
914905
&& !$expr instanceof ArrayDimFetch
906+
&& !$expr instanceof FuncCall
915907
) {
916908
continue;
917909
}
@@ -932,21 +924,6 @@ private function processSureNotTypesForConditionalExpressionsAfterAssign(Scope $
932924
return $conditionalExpressions;
933925
}
934926

935-
private function isBuiltinFunctionCallWithPossibleSideEffects(Expr $expr, Scope $scope): bool
936-
{
937-
if (!$expr instanceof FuncCall || !$expr->name instanceof Name) {
938-
return false;
939-
}
940-
941-
if (!$this->reflectionProvider->hasFunction($expr->name, $scope)) {
942-
return false;
943-
}
944-
945-
$functionReflection = $this->reflectionProvider->getFunction($expr->name, $scope);
946-
947-
return $functionReflection->isBuiltin() && !$functionReflection->hasSideEffects()->no();
948-
}
949-
950927
/**
951928
* @param list<ArrayDimFetch> $dimFetchStack
952929
*/

0 commit comments

Comments
 (0)