-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect invalid key in multi dimensional array fetch
- Loading branch information
Showing
8 changed files
with
166 additions
and
3 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
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,23 @@ | ||
<?php // lint >= 8.1 | ||
|
||
namespace Bug6315; | ||
|
||
enum FooEnum | ||
{ | ||
case A; | ||
case B; | ||
} | ||
|
||
/** | ||
* @param array<int, int> $flatArr | ||
* @param array<int, array<int, int>> $deepArr | ||
* @return void | ||
*/ | ||
function foo(array $flatArr, array $deepArr): void | ||
{ | ||
var_dump($flatArr[FooEnum::A]); | ||
var_dump($deepArr[FooEnum::A][5]); | ||
var_dump($deepArr[5][FooEnum::A]); | ||
var_dump($deepArr[FooEnum::A][FooEnum::B]); | ||
$deepArr[FooEnum::A][] = 5; | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bug6605; | ||
|
||
class X { | ||
public static function doFoo(): void | ||
{ | ||
$x = new X; | ||
$x['invalidoffset'][0] = [ | ||
'foo' => 'bar' | ||
]; | ||
|
||
$arr = ['a' => ['b' => [5]]]; | ||
var_dump($arr['invalid']['c']); | ||
var_dump($arr['a']['invalid']); | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
tests/PHPStan/Rules/Arrays/data/invalid-key-array-item-enum.php
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,16 @@ | ||
<?php // lint >= 8.1 | ||
|
||
namespace InvalidKeyArrayItemEnum; | ||
|
||
enum FooEnum | ||
{ | ||
case A; | ||
case B; | ||
} | ||
|
||
function doFoo(): void | ||
{ | ||
$a = [ | ||
FooEnum::A => 5, | ||
]; | ||
} |