You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.
There are two problems when using Arrays::get($data, $path, $default);
Consider such input:
$data = [
'foo' => null,
];
When $key is a dot notation for a path that doesn't exist, $default is returned. By default, it'd be null. One can work around this problem as $default can be a Closure. Sth like Arrays::get($data, $path, function() { throw new \Exception('Item not found'); }); works but is just a workaround for another problem. Example: Arrays::get($data, 'foo.bar.baz'); returns null.
When $key exists but the value is null, it would be treated as not existing. Example: Arrays::get($data, 'foo', 'the value does not exist'); returns the value does not exist
Both problems stem from the fact of using isset() instead of array_key_exists(). It's trivial to fix the issue but it'd introduce BC breaks.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
There are two problems when using
Arrays::get($data, $path, $default);
Consider such input:
$key
is a dot notation for a path that doesn't exist,$default
is returned. By default, it'd benull
. One can work around this problem as$default
can be a Closure. Sth likeArrays::get($data, $path, function() { throw new \Exception('Item not found'); });
works but is just a workaround for another problem. Example:Arrays::get($data, 'foo.bar.baz');
returnsnull
.$key
exists but the value isnull
, it would be treated as not existing. Example:Arrays::get($data, 'foo', 'the value does not exist');
returnsthe value does not exist
Both problems stem from the fact of using
isset()
instead ofarray_key_exists()
. It's trivial to fix the issue but it'd introduce BC breaks.The text was updated successfully, but these errors were encountered: