Dear Theodore and list,
I’ve been looking into the “Deprecate semicolon after case in switch statement” PHP 8.5 deprecation [1] with the aim of adding a sniff for this to the PHPCompatibility standard and I’m noticing an oddity for which I would like to clarify whether this is intentional or an oversight.
As demonstrated in the example code provided in the deprecation RFC, both switch case
condition statements, as well as default
statements, can be ended with a semicolon.
So when I first read the RFC, I interpreted the proposal to include both case
as well as default
, as, in my mind, default
is just a special case
in a switch.
However, the RFC explicitly only talked about deprecating the use of a semicolon after a case
statement and the implementation has followed this to the letter. [2]
The net result of this, is that you can now have a switch
statement with semicolons terminating case
statements and default
statements, where the former (case
) will result in a deprecation notice, while the latter (default
) will not. For an example, see [3]
This feels inconsistent to me and counter to the intention of the RFC, which is stated to be:
Case statements followed by a semicolon can cause confusion, as a developer may think they behave differently in some way from regular case statements (e.g. preventing fallthrough), when they do not.
Which leaves me wondering what the reason was not to also deprecate the use of a semicolon to terminate a default
statement in a switch ?
I can’t find any discussion about this in the original mailing list thread [4].
Anyone would care to clarify ?
Smile,
Juliette
1: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_semicolon_after_case_in_switch_statement
2: https://github.com/php/php-src/commit/5f8d648af6ef4e29a3c7f2b2029d08466c12bc6f
3: https://3v4l.org/liFIK/rfc#vgit.master
4: https://externals.io/message/126000