-
Notifications
You must be signed in to change notification settings - Fork 28
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
Remove array_get #1356
base: master
Are you sure you want to change the base?
Remove array_get #1356
Conversation
41b30cc
to
0fea8ce
Compare
The function cannot be properly typed as it is and fixing this would take a while, removing it is shorter and better. The change is pretty wide so care should be taken as it is likely to introduce some regressions. I have double-checked the diffs to make sure no regression crept in but it is still possible. TESTS=Did some PM/SA/P1 operations to confirm that those still work.
0fea8ce
to
0f157d4
Compare
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.
This is a lot and I will need to work my way through it.
I'm not against this change, but I do want to ask: does doing this help PHPStan check our code better than using array_get()
without typing? I want to make sure there's some value-add and that we're not doing it just to do it. My comments on the array_get()
function assume the answer is "yes, there is value".
/** | ||
* Return $arr[$key], or if it's not defined, $default. | ||
*/ | ||
function array_get($arr, $key, $default) |
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.
We should not remove this function yet because it's used by code that isn't checked into git (ie: noncvs
code) and perhaps others who use our code.
Instead, we should add typing for the bits we know (array $arr
), set it as @deprecated
, and do a trigger_error("array_get() is deprecated, use the null coalescing operator instead", E_USER_DEPRECATED);
.
Yes, there is value as PHPStan can infer the narrow type of the return/args when using Let's take those 2 equivalent statements: In the first case, PHPStan doesn't know the return of |
|
Yes, it should be able to with a caveat that it needs to know the narrow type of |
@jchaffraix - are you intending on splitting this up into pieces to review separately or would you like help to do that? There's no rush, I just realized it wasn't clear who was taking point on next steps. |
The function cannot be properly typed as it
is and fixing this would take a while, removing
it is shorter and better.