-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Support PHP 8's mixed
type
#2968
Comments
@carusogabriel Yup, that was already on my radar, as well as union types and the static return type.
Want to work on this yourself or would you like me to finish this off ? In which case, I'd be looking for a PHP 8 download for Windows to test with. Would you happen to know where I can find one ? |
I want to give it a try, but if I get stuck or something, I'll let you know!
@cmb69 Do you know where we can find it? We don't keep a |
There are master snapshot builds at https://windows.php.net/downloads/snaps/master/. |
@cmb69 Thanks for the link! That's useful. @carusogabriel Let me know how you get on and if you want me to look something over. Once the initial changes are in ( Depending on how involved the initial changes are, I'd normally wait with making changes to sniffs to get the initial changes approved & accepted, cause if something would be changed in the chosen implementation, the sniff changes might be affected. Have I given you enough to go on with that ? |
@jrfnl Yeah, thank you very much. I'll try to come up with something during the following days, I keep this issue updated |
@jrfnl Sorry for the late noticed, but I didn't find time to work on this 😕 Feel free to close this issue or assign it to someone else. |
@carusogabriel I'm not an admin here, so can't assign or close issues. Aside from that: thanks for letting me know. I had been wondering how you were getting on. I'll see if I can find some time over the next few weeks to sort it out. The constructor property promotion also needs addressing in the same function. |
Methods involved:
Status update:
|
Ok, so I'm running into a decision point - @gsherwood please weight in on this: Type Similarly, with union types, the nullability operator cannot be used and an explicit function foo(mixed $var) {}
function foo(int|float|null $var) {} A decision is needed on how to handle this for the In my perspective, there are two possible approaches:
I'm leaning towards option 1, the functional approach, but would like a second/third/fourth opinion on this. Other considerations: function foo($var = null) {} In my opinion, this is not the same thing as a "type" can only be nullable if a type was declared. Refs: |
The Note that the same behaviour is also present in the getMethodProperties() helper as well, which has a This functionality must remain in version 3 as it would be a significant BC break. I get that the functionality of PHP is changing and the array index name is a bit vague, but it means something very specific in the current release. Version 4 is where we could make changes to this, although I'm more inclined to change the name of the array index (or do nothing) than to change its meaning. I'd need more use cases of where it is important for a coding standards checker to know that a param would accept null, or that a method may return null, so I know if it is worth even returning this. It makes perfect sense for static analysis tools that are checking for coding errors, but probably less so for formatting errors. |
@gsherwood Ok, thanks for pitching in. That means in effect that I'll need to update the documentation of the On another note - how would you prefer I pull the above mentioned PHP 8 related changes to the utility method (
I have made the changes locally in a series of commits, so I can split them out in various ways or pull them in one go, whatever you prefer. |
Update: I've now also checked which sniffs would need adjusting for union types and could only find two for which this applies:
|
I've prepared the necessary changes for supporting constructor property promotion. These can be pulled once #3009 has been merged. |
@gsherwood I've been thinking about the union types a little more and I wonder if it wouldn't be better to change the Reason being that any sniff which currently looks for (bitwise) operators and adjusts the spacing around them would possibly start changing the spacing in union types too, while most of the time, that is not the intention of those sniffs. What do you think ? |
I think you're right. |
@gsherwood Thanks for getting back to me. In that case, it will probably be better to split the PRs on feature rather than on utility method, like I've done now, as all three will need to take the new token into account. I will close the currently open PRs and replace them. First PR will then add tests for mixed type (already works, no extra changes needed). - See PR #3018 |
Re: sniffs which need checking - for constructor property promotion, sniffs which examine namingconventions for properties and function parameters will probably need adjusting. |
PHP 8 has a new type:
mixed
as per this RFC.@jrfnl @gsherwood It shouldn't be that difficult to add support, right? Mind to guide me for this one? 😄
The text was updated successfully, but these errors were encountered: