-
Notifications
You must be signed in to change notification settings - Fork 812
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
Conversation
standard/standard_10.php
Outdated
* @since 8.4 | ||
*/ | ||
function array_find(array $array, callable $callback): mixed {} | ||
function array_find(array $array, callable $callback) {} |
There was a problem hiding this comment.
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
Other test failures are not related to your changes so I'll fix them myself. Could you please just return back mixed
return type?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
@@ -1,5 +1,10 @@ | |||
<?php | |||
/** | |||
* @template TKey |
There was a problem hiding this comment.
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
No description provided.