-
Notifications
You must be signed in to change notification settings - Fork 61
Description
Since it looks like named parameters will pass, with no proposal of having a way to opt out of this feature, I'd like to propose introducing an attribute to have parameter names excluded from BCC rules, by way of annotation.
The main comment I've seen in support of named parameters is that "you can just say you're not supporting named parameters". Unfortunately, just saying that (e.g. by writing in your README.md) doesn't make tools understand that fact, so we need to recognise this some other way. The RFC even goes as far as to mention an "opt-out" possibility, but it never expands on it beyond suggesting an annotation such as <<NoNamedArgs>>
. Therefore, unless another RFC is proposed to add this, we can be fairly sure that there will be no runtime checks to prevent calling a method with named-parameter syntax.
So: onto the proposal: Add an annotation to method definition that says "you must not call this method using named parameter syntax". Static analysers such as Psalm/PHPStan could check this at call-time: I believe Psalm "may" support this if there is demand, and PHPStan are actively looking to support this kind of annotation.
Because there is chance for BC break by renaming parameters with the named param RFC (even if a rename is rare), we will need to add this as a rule now from any PHP 8 code. However, we can use the above annotation to exclude any parameter renames from being marked as BC breaks within this tool.
Before API:
function supportsNamedParams($a, $b, $c);
@@NoNamedParams
function doesNotSupportNamedParams($a, $b, $c);
After API
function supportsNamedParams($d, $e, $f); // would be marked as a BC break due to named params in PHP 8
@@NoNamedParams
function doesNotSupportNamedParams($d, $e, $f); // param renames are ignored due to annotation, not classed as a BC break