Skip to content

Commit

Permalink
fix: arrayHelper.getValue key allow int type
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jan 17, 2020
1 parent 98f9bc8 commit 5372179
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/stdlib/src/Helper/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static function getValue($array, $key, $default = null)
return $array[$key];
}

if (($pos = strrpos($key, '.')) !== false) {
if (is_string($key) && ($pos = strrpos($key, '.')) !== false) {
$array = static::getValue($array, substr($key, 0, $pos), $default);
$key = (string)substr($key, $pos + 1);
}
Expand Down
3 changes: 2 additions & 1 deletion src/stdlib/test/unit/Helper/ArrayHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public function testMerge(): void
public function testGetValue(): void
{
//test base
$arr = ['a' => 1, 'b' => 2];
$arr = ['a' => 1, 'b' => 2, 3];
$rs = ArrayHelper::getValue($arr, 'b');
$this->assertSame(2, $rs);
$this->assertSame(3, ArrayHelper::getValue($arr, 0));

//test get not exist key
$rs2 = ArrayHelper::getValue($arr, 'c');
Expand Down

0 comments on commit 5372179

Please sign in to comment.