Skip to content

Commit

Permalink
Removed isset() micro optimization. It is no longer valid php/php-src…
Browse files Browse the repository at this point in the history
  • Loading branch information
germanow committed Feb 12, 2020
1 parent 35e9d52 commit 6090e8f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ public static function getValue($array, $key, $default = null)
$key = $lastKey;
}

if (is_array($array) && (isset($array[$key]) || array_key_exists($key, $array))) {
if (is_float($key)) {
$key = (int) $key;
}
if (is_array($array) && array_key_exists($key, $array)) {
return $array[$key];
}

Expand All @@ -196,7 +199,7 @@ public static function getValue($array, $key, $default = null)
}

if (is_array($array)) {
return (isset($array[$key]) || array_key_exists($key, $array)) ? $array[$key] : $default;
return array_key_exists($key, $array) ? $array[$key] : $default;
}

return $default;
Expand Down Expand Up @@ -298,7 +301,7 @@ public static function setValue(array &$array, $path, $value): void
*/
public static function remove(array &$array, string $key, $default = null)
{
if (isset($array[$key]) || array_key_exists($key, $array)) {
if (array_key_exists($key, $array)) {
$value = $array[$key];
unset($array[$key]);

Expand Down Expand Up @@ -583,9 +586,7 @@ public static function map(array $array, $from, $to, $group = null): array
public static function keyExists(array $array, string $key, bool $caseSensitive = true): bool
{
if ($caseSensitive) {
// Function `isset` checks key faster but skips `null`, `array_key_exists` handles this case
// http://php.net/manual/en/function.array-key-exists.php#107786
return isset($array[$key]) || array_key_exists($key, $array);
return array_key_exists($key, $array);
}

foreach (array_keys($array) as $k) {
Expand Down

0 comments on commit 6090e8f

Please sign in to comment.