-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix false positive non-existing-offset after array_search()
- Loading branch information
Showing
3 changed files
with
74 additions
and
1 deletion.
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
37 changes: 37 additions & 0 deletions
37
tests/PHPStan/Rules/Arrays/data/array-dim-after-array-search.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,37 @@ | ||
<?php // lint >= 8.0 | ||
|
||
declare(strict_types = 1); | ||
|
||
namespace ArrayDimAfterArraySeach; | ||
|
||
class HelloWorld | ||
{ | ||
public function doFoo(array $arr, string $needle): string | ||
{ | ||
if (($key = array_search($needle, $arr, true)) !== false) { | ||
echo $arr[$key]; | ||
} | ||
} | ||
|
||
public function doBar(array $arr, string $needle): string | ||
{ | ||
$key = array_search($needle, $arr, true); | ||
if ($key !== false) { | ||
echo $arr[$key]; | ||
} | ||
} | ||
|
||
public function doFooBar(array $arr, string $needle): string | ||
{ | ||
if (($key = array_search($needle, $arr, false)) !== false) { | ||
echo $arr[$key]; | ||
} | ||
} | ||
|
||
public function doBaz(array $arr, string $needle): string | ||
{ | ||
if (($key = array_search($needle, $arr)) !== false) { | ||
echo $arr[$key]; | ||
} | ||
} | ||
} |