mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 22:30:27 +08:00
Fixes #9915: yii\helpers\ArrayHelper::getValue()
was erroring instead of returning null
for non-existing object properties
This commit is contained in:
@ -24,6 +24,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #9874: Fixed outputting exception stacktrace in non-debug mode when `Response::FORMAT_RAW` is used (nainoon)
|
||||
- Bug #9883: Passing a single `yii\db\Expression` to `Query::select()` or `::addSelect()` was not handled correctly in all cases (cebe)
|
||||
- Bug #9911: Fixed `yii\helpers\BaseStringHelper::explode()` code so it does not remove items eq to 0 with skip_empty attribute (silverfire, kidol)
|
||||
- Bug #9915: `yii\helpers\ArrayHelper::getValue()` was erroring instead of returning `null` for non-existing object properties (totaldev, samdark)
|
||||
- Bug: Fixed generation of canonical URLs for `ViewAction` pages (samdark)
|
||||
- Enh #7581: Added ability to specify range using anonymous function in `RangeValidator` (RomeroMsk)
|
||||
- Enh #8613: `yii\widgets\FragmentCache` will not store empty content anymore which fixes some problems related to `yii\filters\PageCache` (kidol)
|
||||
|
@ -198,7 +198,7 @@ class BaseArrayHelper
|
||||
$key = substr($key, $pos + 1);
|
||||
}
|
||||
|
||||
if (is_object($array)) {
|
||||
if (is_object($array) && isset($array->$key)) {
|
||||
return $array->$key;
|
||||
} elseif (is_array($array)) {
|
||||
return array_key_exists($key, $array) ? $array[$key] : $default;
|
||||
|
@ -385,6 +385,13 @@ class ArrayHelperTest extends TestCase
|
||||
$this->assertEquals($expected, ArrayHelper::getValue($array, $key, $default));
|
||||
}
|
||||
|
||||
public function testGetValueObjects()
|
||||
{
|
||||
$object = new Post1();
|
||||
$this->assertEquals(23, ArrayHelper::getValue($object, 'id'));
|
||||
$this->assertEquals(null, ArrayHelper::getValue($object, 'nonExisting'));
|
||||
}
|
||||
|
||||
public function testIsAssociative()
|
||||
{
|
||||
$this->assertFalse(ArrayHelper::isAssociative('test'));
|
||||
|
Reference in New Issue
Block a user