-
-
Notifications
You must be signed in to change notification settings - Fork 28
Open
Labels
status:ready for adoptionFeel free to implement this issue.Feel free to implement this issue.
Description
What the problem?
Lines 210 to 212 in c3d14a3
if ($key instanceof Closure) { | |
return $key($array, $default); | |
} |
Current implementation of getValue($array, $key)
with $key as anonymous function is not match with the phrases Retrieves the value of an array element
. basically it just like a value transformation, it can returns anything even value from outside array itself as of in example
Lines 184 to 188 in c3d14a3
* // Working with anonymous function: | |
* $fullName = \Yiisoft\Arrays\ArrayHelper::getValue($user, function ($user, $defaultValue) { | |
* return $user->firstName . ' ' . $user->lastName; | |
* }); | |
* |
What is the expected result?
the implementation should search value of an array by matcher function
if ($key instanceof Closure) {
foreach ($array as $key => $value) {
if ($key($value, $key)) {
return $value;
}
}
return $default;
}
and then, change the signature of matcher function to be function($value, $key): bool
.
Additional info
Q | A |
---|---|
Version | 1.0.? |
PHP version | |
Operating system |
Metadata
Metadata
Assignees
Labels
status:ready for adoptionFeel free to implement this issue.Feel free to implement this issue.