Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] PHPDoc Improvements #53097

Merged
merged 1 commit into from
Oct 10, 2024
Merged

Conversation

schulerj89
Copy link
Contributor

Update the PHPDoc to the Arr::exists function to show it also accepts float as a param value

> Arr::exists(['1.2' => 1], 1.2);
= true

@rodrigopedra
Copy link
Contributor

At first, I thought on arguing against this PR, as one could say to also add boolean to the list:

> Arr::exists([1 => 1], true)
= true

But after looking into the source, the Arr::exists() explicitly checks if the key is a float, thus behaving differently from the array_key_exists() PHP function, which would truncate the float to an integer.

public static function exists($array, $key)
{
if ($array instanceof Enumerable) {
return $array->has($key);
}
if ($array instanceof ArrayAccess) {
return $array->offsetExists($key);
}
if (is_float($key)) {
$key = (string) $key;
}
return array_key_exists($key, $array);
}

As such, I guess it is best to add the type hint.

@taylorotwell taylorotwell merged commit 53c1d50 into laravel:11.x Oct 10, 2024
33 checks passed
timacdonald pushed a commit to timacdonald/framework that referenced this pull request Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants