Skip to content

Commit 6090e8f

Browse files
committed
Removed isset() micro optimization. It is no longer valid php/php-src#3360
1 parent 35e9d52 commit 6090e8f

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/ArrayHelper.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ public static function getValue($array, $key, $default = null)
180180
$key = $lastKey;
181181
}
182182

183-
if (is_array($array) && (isset($array[$key]) || array_key_exists($key, $array))) {
183+
if (is_float($key)) {
184+
$key = (int) $key;
185+
}
186+
if (is_array($array) && array_key_exists($key, $array)) {
184187
return $array[$key];
185188
}
186189

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

198201
if (is_array($array)) {
199-
return (isset($array[$key]) || array_key_exists($key, $array)) ? $array[$key] : $default;
202+
return array_key_exists($key, $array) ? $array[$key] : $default;
200203
}
201204

202205
return $default;
@@ -298,7 +301,7 @@ public static function setValue(array &$array, $path, $value): void
298301
*/
299302
public static function remove(array &$array, string $key, $default = null)
300303
{
301-
if (isset($array[$key]) || array_key_exists($key, $array)) {
304+
if (array_key_exists($key, $array)) {
302305
$value = $array[$key];
303306
unset($array[$key]);
304307

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

591592
foreach (array_keys($array) as $k) {

0 commit comments

Comments
 (0)