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

Leverage new array functions #424

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

derrabus
Copy link
Member

PHP 8.4 will add a couple of array functions that we can make use of:

https://wiki.php.net/rfc/array_find

I'm using Symfony's polyfill to make sure the functions are always available. If we don't want to add that dependency, we could also work with a PHP version check inside the methods I've changed.

@derrabus derrabus added this to the 2.3.0 milestone Aug 27, 2024
@derrabus derrabus marked this pull request as ready for review August 27, 2024 08:36
@derrabus derrabus requested a review from greg0ire August 27, 2024 08:36
greg0ire
greg0ire previously approved these changes Aug 27, 2024
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK with the polyfill… it's an extra dependency, but tiny, likely to be already installed, and not here to stay.

* @template TKey of array-key
* @template TValue
*/
function array_find(array $array, callable $callback): mixed {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is a stub needed for this function but not the others?

Copy link
Member Author

@derrabus derrabus Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Psalm does not know about the new functions yet. We need this stub, so Psalm can infer the correct return type for array_find(). The other two new functions I've used always return a boolean, so the native return types might be just good enough.

@derrabus derrabus merged commit 1a882ec into doctrine:2.3.x Aug 28, 2024
9 checks passed
@derrabus derrabus deleted the improvement/array-find branch August 28, 2024 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants