Skip to content

Commit 3f70082

Browse files
VincentLangletondrejmirtes
authored andcommitted
Fix for BenevolentUnion
1 parent 5049143 commit 3f70082

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/Type/UnionType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ public function isScalar(): TrinaryLogic
676676

677677
public function looseCompare(Type $type, PhpVersion $phpVersion): BooleanType
678678
{
679-
return $this->unionResults(
679+
return $this->notBenevolentUnionResults(
680680
static fn (Type $innerType): TrinaryLogic => $innerType->looseCompare($type, $phpVersion)->toTrinaryLogic()
681681
)->toBooleanType();
682682
}

tests/PHPStan/Rules/Comparison/ConstantLooseComparisonRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,10 @@ public function testBug8800(): void
242242
]);
243243
}
244244

245+
public function testBug13098(): void
246+
{
247+
$this->treatPhpDocTypesAsCertain = true;
248+
$this->analyse([__DIR__ . '/data/bug-13098.php'], []);
249+
}
250+
245251
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Bug13098;
4+
5+
$x = substr($_GET["x"], 0, 10);
6+
if ($x == "") echo "empty";
7+
8+
$x = get_include_path();
9+
if ($x == "") echo "empty";
10+
11+
$x = password_hash("password", PASSWORD_DEFAULT);
12+
if ($x == false) echo "false";
13+
14+
$x = php_sapi_name();
15+
if ($x == false) echo "false";

0 commit comments

Comments
 (0)