-
Notifications
You must be signed in to change notification settings - Fork 650
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
Fix mb_convert_encoding to accept any array. #6910
Conversation
Thanks! Do you know if the shape of the array is preserved? If it is, we could create a stub in order to make the array shape pass through the function. something like
should do the trick |
Running tests locally at the moment… Hmm, no, it isn’t. Look at the last example in the issue. String keys are translated, objects/recursively referenced values are replaced. So I guess, no |
Tests shouldn't be that slow, even with Xdebug enabled (I'd suggest to disable it with, e.g. https://packagist.org/packages/weirdan/run-without-xdebug though). |
Yeah, string are transformed, but the general shape of the array is kept, no? I mean, if the array was |
Yeah, but |
@weirdan Yep. |
It takes about 5 minutes here, using |
@weirdan gonna try, but I’m already at 44% now – almost done :-) |
Oh yeah, forgot about literals in array-shapes. Guess it would need a return type provider in order to recursively strip any string literal. It may be worth it one day, returning |
Probably
Would help for most cases |
Yeah, it would, Mind adding that to the stubs? |
@orklah ok |
Note that you have to make a change to CallMap_80 and possibly CallMap_historical for your PR to pass the CI. More is explained here: https://psalm.dev/docs/contributing/editing_callmaps/ |
@orklah CoreGenericFunctions.phpstub? Just add it at the end? |
How do you like this format:
I like it that way because it lists all possible options and is quite readable that way. |
Please don't add never at the end. Listing the allowed params is enough to make Psalm emit an issue. Adding never will just create a whole new set of weird errors that will be irrelevant |
@orklah ok. Looking at the other callmaps now… If I see it right, I'll have to remove the array version from CallMap_historical.php, add it to 'added' CallMap_72_delta.php?! |
nah, you have to change the signature in CallMap_80 "new" to match with the one in your CallMap file and then, if needed, change the CallMap_historical to match with the CallMap_80 "old" (we start from CallMap and then process each delta file from newer to older untli CallMap_historical) |
I think I have it, running tests… |
@@ -34,6 +34,7 @@ | |||
'ldap_exop_whoami' => ['string|false', 'ldap'=>'resource'], | |||
'ldap_parse_exop' => ['bool', 'ldap'=>'resource', 'result'=>'resource', '&w_response_data='=>'string', '&w_response_oid='=>'string'], | |||
'mb_chr' => ['string|false', 'codepoint'=>'int', 'encoding='=>'string'], | |||
'mb_convert_encoding\'1' => ['array', 'string'=>'array', 'to_encoding'=>'string', 'from_encoding='=>'mixed'], |
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.
Oh, nice catch! I didn't know arrays were introduced in 7.2
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.
At least the manual says so :-)
stubs/CoreGenericFunctions.phpstub
Outdated
* @template T of array|string | ||
* @param T $string | ||
* @return (T is array<int, string> ? array<int, string> : T is array ? array : string) |
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 add |false everywhere in the return types
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.
Ah, good catch. But only at the string return.
I still wonder what happens, when you add a string that triggers returning false for a string into an array…
Can you add a |
@orklah Here you are :-) |
Thank you! That's great! |
No, I have to thank for this great tool! |
Fixes #6886