diff --git a/framework/helpers/base/ArrayHelper.php b/framework/helpers/base/ArrayHelper.php index 4802651..e482883 100644 --- a/framework/helpers/base/ArrayHelper.php +++ b/framework/helpers/base/ArrayHelper.php @@ -95,7 +95,7 @@ class ArrayHelper * ~~~ * // $array = array('type'=>'A', 'options'=>array(1,2)); * // working with array - * $type = \yii\helpers\ArrayHelper::popValue($array, 'type'); + * $type = \yii\helpers\ArrayHelper::remove($array, 'type'); * // $array content * // $array = array('options'=>array(1,2)); * ~~~ @@ -105,10 +105,10 @@ class ArrayHelper * @param mixed $default the default value to be returned if the specified key does not exist * @return mixed|null the value of the element if found, default value otherwise */ - public static function popValue(&$array, $key, $default = null) + public static function remove(&$array, $key, $default = null) { - if (is_array($array)) { - $value = static::getValue($array, $key, $default); + if (is_array($array) && (isset($array[$key]) || array_key_exists($key, $array))) { + $value = $array[$key]; unset($array[$key]); return $value; } diff --git a/tests/unit/framework/helpers/ArrayHelperTest.php b/tests/unit/framework/helpers/ArrayHelperTest.php index 897fcf7..8c83278 100644 --- a/tests/unit/framework/helpers/ArrayHelperTest.php +++ b/tests/unit/framework/helpers/ArrayHelperTest.php @@ -12,10 +12,10 @@ class ArrayHelperTest extends \yii\test\TestCase } - public function testPopvalue() + public function testRemove() { $array = array('name' => 'b', 'age' => 3); - $name = ArrayHelper::popValue($array, 'name'); + $name = ArrayHelper::remove($array, 'name'); $this->assertEquals($name, 'b'); $this->assertEquals($array, array('age' => 3));