Skip to content

Add generics to array_find #1752

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

Merged
merged 2 commits into from
Jun 13, 2025
Merged

Add generics to array_find #1752

merged 2 commits into from
Jun 13, 2025

Conversation

JurianArie
Copy link
Contributor

No description provided.

* @since 8.4
*/
function array_find(array $array, callable $callback): mixed {}
function array_find(array $array, callable $callback) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

@JurianArie return type should stay here to match reflection data. And a failing test notifies about this
Screenshot 2025-06-12 at 16 48 56
Other test failures are not related to your changes so I'll fix them myself. Could you please just return back mixed return type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@isfedorov adding mixed here is not ideal as it will result in PhpStorm always adding mixed to the type:

array_find([1, 2, 3], fn () => true)

function array_find(
    array $array,
    callable $callback
): int|mixed|null

Copy link
Contributor

Choose a reason for hiding this comment

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

is not ideal as it will result in PhpStorm always adding mixed to the type

This is a problem on PhpStorm's side then and it shouldn't be workarounded by tweaking the stubs in this case. PhpStorm just should filter out mixed type and leave only type inferred based on generic. And actually there is a similar request WI-79472

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mixed type has been added back. That issue does indeed look related!

@isfedorov isfedorov merged commit ccd0bd6 into JetBrains:master Jun 13, 2025
10 of 12 checks passed
@@ -1,5 +1,10 @@
<?php
/**
* @template TKey
Copy link
Contributor

Choose a reason for hiding this comment

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

similar generics would be useful for other array_* functions in this file

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