Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<phpunit colors="true" failOnWarning="true">
<testsuites>
<testsuite name="Complex">
<directory suffix="Test.php">./test</directory>
Expand All @@ -13,4 +13,4 @@
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
</phpunit>
4 changes: 2 additions & 2 deletions src/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static function has(array $array, $keys): bool
$tmp = $array;

foreach ($keysArray as $key) {
if (!array_key_exists($key, $tmp)) {
if (!is_array($tmp) || !array_key_exists($key, $tmp)) {
return false;
}
$tmp = $tmp[$key];
Expand Down Expand Up @@ -1323,4 +1323,4 @@ public static function obj($array = []): ArrObj
{
return new ArrObj($array);
}
}
}
9 changes: 8 additions & 1 deletion test/Arr/ArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function testHas($class)
[
'test6' => 'def'
],
'test7' => [],
'test8' => null,
],
];

Expand All @@ -53,6 +55,11 @@ public function testHas($class)
$this->assertFalse($this->callMethod([$class, 'has'], $array, 'test2'));
$this->assertFalse($this->callMethod([$class, 'has'], $array, 'test.test1'));
$this->assertFalse($this->callMethod([$class, 'has'], $array, 'test.test2.test4'));

$this->assertFalse($this->callMethod([$class, 'has'], $array, 'test.test2.test3.foo'));
$this->assertFalse($this->callMethod([$class, 'has'], $array, 'test.test7.foo'));
$this->assertFalse($this->callMethod([$class, 'has'], $array, 'test.test8.foo'));
$this->assertFalse($this->callMethod([$class, 'has'], $array, '1.2.3'));
}

/**
Expand Down Expand Up @@ -1734,4 +1741,4 @@ public static function testStaticTwoArg($value, $key)
{
return $key < 3 && $value;
}
}
}