-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support AssignOp\Coalesce in CoalesceRule, add test cases for ArrayDi…
…mFetch
- Loading branch information
1 parent
c98b3fb
commit b098255
Showing
4 changed files
with
150 additions
and
25 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,55 @@ | ||
<?php // lint >= 7.4 | ||
|
||
function coalesceAssign () | ||
{ | ||
|
||
$scalar = 3; | ||
|
||
echo $scalar ??= 4; | ||
|
||
$array = [1, 2, 3]; | ||
|
||
echo $array['string'] ??= 0; | ||
|
||
$multiDimArray = [[1], [2], [3]]; | ||
|
||
echo $multiDimArray['string'] ??= 0; | ||
|
||
echo $doesNotExist ??= 0; | ||
|
||
if(rand() > 0.5) { | ||
$maybeVariable = 3; | ||
} | ||
|
||
echo $maybeVariable ??= 0; | ||
|
||
$fixedDimArray = [ | ||
'dim' => 1, | ||
'dim-null' => rand() > 0.5 ? null : 1, | ||
'dim-null-offset' => ['a' => rand() > 0.5 ? true : null], | ||
'dim-empty' => [] | ||
]; | ||
|
||
// Always set | ||
echo $fixedDimArray['dim'] ??= 0; | ||
|
||
// Maybe set | ||
echo $fixedDimArray['dim-null'] ??= 0; | ||
|
||
// Never set, then unknown | ||
echo $fixedDimArray['dim-null-not-set']['a'] ??= 0; | ||
|
||
// Always set, then always set | ||
echo $fixedDimArray['dim-null-offset']['a'] ??= 0; | ||
|
||
// Always set, then never set | ||
echo $fixedDimArray['dim-empty']['b'] ??= 0; | ||
} | ||
|
||
/** | ||
* @param array<string, int> $array | ||
*/ | ||
function coalesceAssignStringOffset(array $array) | ||
{ | ||
echo $array['string'] ??= 0; | ||
} |
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