Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make key_exists be treated like array_key_exists
- Loading branch information
1 parent
acbb55b
commit 3552fe3
Showing
5 changed files
with
81 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
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,29 @@ | ||
<?php | ||
|
||
namespace KeyExists; | ||
|
||
use function key_exists; | ||
use function PHPStan\Testing\assertType; | ||
|
||
class KeyExists | ||
{ | ||
/** | ||
* @param array<string, string> $a | ||
* @return void | ||
*/ | ||
public function doFoo(array $a, string $key): void | ||
{ | ||
assertType('false', key_exists(2, $a)); | ||
assertType('bool', key_exists('foo', $a)); | ||
assertType('false', key_exists('2', $a)); | ||
|
||
$a = ['foo' => 2, 3 => 'bar']; | ||
assertType('true', key_exists('foo', $a)); | ||
assertType('true', key_exists('3', $a)); | ||
assertType('false', key_exists(4, $a)); | ||
|
||
$empty = []; | ||
assertType('false', key_exists('foo', $empty)); | ||
assertType('false', key_exists($key, $empty)); | ||
} | ||
} |