mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-01 20:19:42 +08:00
Fix #18505: Fixed ArrayHelper::get() for ArrayAccess objects with explicitly defined properties
Co-authored-by: Bizley <pawel@positive.codes>
This commit is contained in:
committed by
GitHub
parent
95c2d214d9
commit
71791d790d
@ -17,6 +17,7 @@ Yii Framework 2 Change Log
|
|||||||
- Enh #18493: Faster request parsing for REST UrlRule with prefix handling (bizley)
|
- Enh #18493: Faster request parsing for REST UrlRule with prefix handling (bizley)
|
||||||
- Enh #18487: Allow creating URLs for non-GET-verb rules (bizley)
|
- Enh #18487: Allow creating URLs for non-GET-verb rules (bizley)
|
||||||
- Bug #8750: Fix MySQL support when running in `ANSI`/`ANSI_QUOTES` modes (brandonkelly)
|
- Bug #8750: Fix MySQL support when running in `ANSI`/`ANSI_QUOTES` modes (brandonkelly)
|
||||||
|
- Bug #18505: Fixed `yii\helpers\ArrayHelper::getValue()` for ArrayAccess objects with explicitly defined properties (samdark)
|
||||||
|
|
||||||
|
|
||||||
2.0.40 December 23, 2020
|
2.0.40 December 23, 2020
|
||||||
|
|||||||
@ -196,6 +196,10 @@ class BaseArrayHelper
|
|||||||
$key = $lastKey;
|
$key = $lastKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_object($array) && property_exists($array, $key)) {
|
||||||
|
return $array->$key;
|
||||||
|
}
|
||||||
|
|
||||||
if (static::keyExists($key, $array)) {
|
if (static::keyExists($key, $array)) {
|
||||||
return $array[$key];
|
return $array[$key];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ namespace yiiunit\framework\helpers;
|
|||||||
use ArrayAccess;
|
use ArrayAccess;
|
||||||
use Iterator;
|
use Iterator;
|
||||||
use yii\base\BaseObject;
|
use yii\base\BaseObject;
|
||||||
|
use yii\base\Model;
|
||||||
use yii\data\Sort;
|
use yii\data\Sort;
|
||||||
use yii\helpers\ArrayHelper;
|
use yii\helpers\ArrayHelper;
|
||||||
use yiiunit\TestCase;
|
use yiiunit\TestCase;
|
||||||
@ -122,6 +123,23 @@ class TraversableArrayAccessibleObject extends ArrayAccessibleObject implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MagicModel extends Model
|
||||||
|
{
|
||||||
|
protected $magic;
|
||||||
|
|
||||||
|
public function getMagic()
|
||||||
|
{
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
|
||||||
|
private $moreMagic;
|
||||||
|
|
||||||
|
public function getMoreMagic()
|
||||||
|
{
|
||||||
|
return 'ta-da';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group helpers
|
* @group helpers
|
||||||
*/
|
*/
|
||||||
@ -1536,4 +1554,15 @@ class ArrayHelperTest extends TestCase
|
|||||||
$this->assertEquals(123, ArrayHelper::getValue($data, 'value'));
|
$this->assertEquals(123, ArrayHelper::getValue($data, 'value'));
|
||||||
$this->assertEquals('bar1', ArrayHelper::getValue($data, 'name'));
|
$this->assertEquals('bar1', ArrayHelper::getValue($data, 'name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://github.com/yiisoft/yii2/commit/35fb9c624893855317e5fe52e6a21f6518a9a31c changed the way
|
||||||
|
* ArrayHelper works with existing object properties in case of ArrayAccess.
|
||||||
|
*/
|
||||||
|
public function testArrayAccessWithMagicProperty()
|
||||||
|
{
|
||||||
|
$model = new MagicModel();
|
||||||
|
$this->assertEquals(42, ArrayHelper::getValue($model, 'magic'));
|
||||||
|
$this->assertEquals('ta-da', ArrayHelper::getValue($model, 'moreMagic'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user