Conversation
…tlyNullableParam` sniff (RFC) > - Core: > . Implicitly nullable parameter types are now deprecated. > RFC: https://wiki.php.net/rfc/deprecate-implicitly-nullable-types As this deprecation looks to be high frequency - 880 packages out of the top 2000 Composer packages affected and that's just the tip of the iceberg -, I figured it would be good to have a sniff available early. The fix for the issue is relatively easy and there are multiple options available, though some could result in BC-breaks for the package making the fix. Includes tests and documentation. Refs: * https://wiki.php.net/rfc/deprecate-implicitly-nullable-types * https://github.com/php/php-src/blob/330cc5cdb2096c5d41041eaae1f1cc0ed7e36898/UPGRADING#L271C1-L273C70 * php/php-src 12959 * php/php-src@330cc5c Partially based on PR 1689 Co-authored-by: Dan Wallis <dan@wallis.nz>
Just to clarify for anyone coming to this issue that this would only be the case for packages supporting PHP <= 7.0. This 3v4l example demonstrates the options. |
andrewnicols
left a comment
There was a problem hiding this comment.
This Snfif looks good to me. I know that PHPCompatibility rarely fixes things, but this one is going to be a pain in the back side for a whole lot of developers in a lot of places, and is really pretty easy to fix.
Obviously this one is up to you as maintainer but if you aren't going to include this, I'll be copying this sniff and adding the fix to our local ruleset anyway ;)
PHPCompatibility/Sniffs/FunctionDeclarations/RemovedImplicitlyNullableParamSniff.php
Show resolved
Hide resolved
andrewnicols
left a comment
There was a problem hiding this comment.
Ah, I've just seen your response re auto-fix on #1689 so changing my response to an Approve.
I'll keep my suggestion here because, for the vast majority of projects, it will be probably be sufficient.
@andrewnicols I would warn you off from copying the sniff as you would be violating copyright (and offending me). If you want the most obvious solution - making the parameter nullable - and your codebase's minimum PHP version allows for it, I would recommend you include the |
No offense is intended. My understanding was that this sniff is licensed under the LGPL3 though, which I understood would permit copying and modifying as required. In any case, I do not intend to upset or offend.
The Slevomat sniff is absoltuely massive and has a number of bloated dependencies that we are keen to avoid. This is not a set and forget situation for us as our community has hundreds of plugins that need to be updated in the same way. I had planned to write my own Sniff so I guess I'll go back down that road. |
IANAL, but as far as I understand it, forking and updating (while retaining the original commits and copyright) is okay. Copying, adjusting and then passing it off as your own, is not.
Could you elaborate on that ? I mean: the Slevomat sniff collection is large, true, but you would only be using one sniff of it in this case. So, you're only really talking about the |
PHP 8.4 | ✨ New
PHPCompatibility.FunctionDeclarations.RemovedImplicitlyNullableParamsniff (RFC)As this deprecation looks to be high frequency - 880 packages out of the top 2000 Composer packages affected and that's just the tip of the iceberg -, I figured it would be good to have a sniff available early.
The fix for the issue is relatively easy and there are multiple options available, though some could result in BC-breaks for the package making the fix.
Includes tests and documentation.
Refs:
Closes #1689