-
Notifications
You must be signed in to change notification settings - Fork 470
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix resolving type of isset($arr['key'])
It was buggy when $arr['key'] might be null. Fixes phpstan/phpstan#1924
- Loading branch information
1 parent
2164616
commit 9ea485b
Showing
3 changed files
with
44 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Bug1924; | ||
|
||
use function PHPStan\Analyser\assertType; | ||
|
||
class Bug1924 | ||
{ | ||
|
||
function getArrayOrNull(): ?array | ||
{ | ||
return rand(0, 1) ? [1, 2, 3] : null; | ||
} | ||
|
||
function foo(): void | ||
{ | ||
$arr = [ | ||
'a' => $this->getArrayOrNull(), | ||
'b' => $this->getArrayOrNull(), | ||
]; | ||
assertType('array(\'a\' => array|null, \'b\' => array|null)', $arr); | ||
|
||
$cond = isset($arr['a']) && isset($arr['b']); | ||
assertType('bool', $cond); | ||
} | ||
|
||
} |