From 01c84e2ff2c9d41a8deff55ccb9d826ac876cdd1 Mon Sep 17 00:00:00 2001 From: wanghui Date: Thu, 12 May 2016 11:25:09 +0800 Subject: [PATCH] Fixes #11549: Fixed `ArrayHelper::getValue()` to work properly with float keys --- framework/CHANGELOG.md | 1 + framework/helpers/BaseArrayHelper.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index c8bac20b8c..8029a4ce3c 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -32,6 +32,7 @@ Yii Framework 2 Change Log - Bug #11735: Fixed `yii\web\UploadedFile` to return `null` when there's no file uploaded (brummm) - Bug #11774: Fixed incorrect recusuive symlinks check in FileHelper (AnikanovD) - Bug #11739: Fixed `ArrayHelper::index()` losing precision for float keys (AnikanovD) +- Bug #11549: Fixed `ArrayHelper::getValue()` to work properly with float keys (zsounder, AnikanovD) 2.0.8 April 28, 2016 -------------------- diff --git a/framework/helpers/BaseArrayHelper.php b/framework/helpers/BaseArrayHelper.php index 225479372e..ea0fb62e75 100644 --- a/framework/helpers/BaseArrayHelper.php +++ b/framework/helpers/BaseArrayHelper.php @@ -189,7 +189,7 @@ class BaseArrayHelper $key = $lastKey; } - if (is_array($array) && array_key_exists($key, $array)) { + if (is_array($array) && (isset($array[$key]) || array_key_exists($key, $array)) ) { return $array[$key]; } @@ -203,7 +203,7 @@ class BaseArrayHelper // it is not reliably possible to check whether a property is accessable beforehand return $array->$key; } elseif (is_array($array)) { - return array_key_exists($key, $array) ? $array[$key] : $default; + return (isset($array[$key]) || array_key_exists($key, $array)) ? $array[$key] : $default; } else { return $default; }