Skip to content

Commit fcb78d9

Browse files
committed
isset() - truthy vs. true
1 parent 3b21093 commit fcb78d9

File tree

4 files changed

+86
-2
lines changed

4 files changed

+86
-2
lines changed

src/Analyser/TypeSpecifier.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -538,9 +538,9 @@ public function specifyTypesInCondition(
538538
(
539539
$expr instanceof Expr\Isset_
540540
&& count($expr->vars) > 0
541-
&& $context->truthy()
541+
&& $context->true()
542542
)
543-
|| ($expr instanceof Expr\Empty_ && $context->falsey())
543+
|| ($expr instanceof Expr\Empty_ && $context->false())
544544
) {
545545
$vars = [];
546546
if ($expr instanceof Expr\Isset_) {

tests/PHPStan/Analyser/NodeScopeResolverTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -10209,6 +10209,16 @@ public function dataCount(): array
1020910209
return $this->gatherAssertTypes(__DIR__ . '/data/count-type.php');
1021010210
}
1021110211

10212+
public function dataBug2816(): array
10213+
{
10214+
return $this->gatherAssertTypes(__DIR__ . '/data/bug-2816.php');
10215+
}
10216+
10217+
public function dataBug2816Two(): array
10218+
{
10219+
return $this->gatherAssertTypes(__DIR__ . '/data/bug-2816-2.php');
10220+
}
10221+
1021210222
public function dataBug3985(): array
1021310223
{
1021410224
return $this->gatherAssertTypes(__DIR__ . '/data/bug-3985.php');
@@ -10298,6 +10308,8 @@ public function dataBug3985(): array
1029810308
* @dataProvider dataBug1924
1029910309
* @dataProvider dataExtraIntTypes
1030010310
* @dataProvider dataCount
10311+
* @dataProvider dataBug2816
10312+
* @dataProvider dataBug2816Two
1030110313
* @dataProvider dataBug3985
1030210314
* @param string $assertType
1030310315
* @param string $file
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Bug2816;
4+
5+
use PHPStan\TrinaryLogic;
6+
use function PHPStan\Analyser\assertType;
7+
use function PHPStan\Analyser\assertVariableCertainty;
8+
9+
if (isset($_GET['x'])) {
10+
$a = 1;
11+
}
12+
13+
assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
14+
assertType('mixed', $a);
15+
16+
if (isset($a)) {
17+
echo "hello";
18+
assertVariableCertainty(TrinaryLogic::createYes(), $a);
19+
assertType('mixed~null', $a);
20+
} else {
21+
assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
22+
}
23+
24+
assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
25+
assertType('mixed', $a);
26+
27+
if (isset($a)) {
28+
echo "hello2";
29+
assertVariableCertainty(TrinaryLogic::createYes(), $a);
30+
assertType('mixed~null', $a);
31+
} else {
32+
assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
33+
}
34+
35+
assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
36+
assertType('mixed', $a);
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Bug2816;
4+
5+
use PHPStan\TrinaryLogic;
6+
use function PHPStan\Analyser\assertType;
7+
use function PHPStan\Analyser\assertVariableCertainty;
8+
9+
if (isset($_GET['x'])) {
10+
$a = 1;
11+
}
12+
13+
assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
14+
assertType('mixed', $a);
15+
16+
if (isset($a) === true) {
17+
echo "hello";
18+
assertVariableCertainty(TrinaryLogic::createYes(), $a);
19+
assertType('mixed~null', $a);
20+
} else {
21+
assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
22+
}
23+
24+
assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
25+
assertType('mixed', $a);
26+
27+
if (isset($a) === true) {
28+
echo "hello2";
29+
assertVariableCertainty(TrinaryLogic::createYes(), $a);
30+
assertType('mixed~null', $a);
31+
} else {
32+
assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
33+
}
34+
35+
assertVariableCertainty(TrinaryLogic::createMaybe(), $a);
36+
assertType('mixed', $a);

0 commit comments

Comments
 (0)