Re: Re: Inconsistency in PHP 8.5 deprecation of terminating case with semicolon
| From: | Juliette Reinders Folmer | Date: | Wed, 15 Oct 2025 13:10:53 +0000 |
| Subject: | Re: Re: Inconsistency in PHP 8.5 deprecation of terminating case with semicolon | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128843@lists.php.net to get a copy of this message | ||
On 15-10-2025 6:21, Theodore Brown wrote:
On Tue, October 14 2025 at 18:08 Juliette Reinders Folmer wrote:Hi Theodore, Ah! That explains it. Bugs happen to the best of us. Glad to hear I didn't misunderstand the intention of the RFC. Thanks for clarifying and for the new PR to update the deprecation implementation. Here's me hoping it will be merged soon. Smile, JulietteDear 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 switchHi Juliette, Thank you for pointing out the discrepancy. You are correct thatcasecondition statements, as well asdefaultstatements, can be ended with a semicolon. So when I first read the RFC, I interpreted the proposal to include bothcaseas well asdefault, as, in my mind,defaultis just a specialcasein a switch. However, the RFC explicitly only talked about deprecating the use of a semicolon after acasestatement and the implementation has followed this to the letter. [2] The net result of this, is that you can now have aswitchstatement with semicolons terminatingcasestatements anddefaultstatements, 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 adefaultstatement in a switch ? I can't find any discussion about this in the original mailing list thread [4]. Anyone would care to clarify ?defaultis just a special case statement, and the intention in the RFC was to output the deprecation message for default cases as well (the example in the RFC included a default case followed by a semicolon to highlight this). The fact that a deprecation message isn't shown for default cases is an oversight on my part when I implemented the RFC. The merged implementation correctly updated the AST for default case statements followed by a semicolon to support the deprecation message, but I failed to notice that when the compiler code loops over switch cases, there is acontinuestatement when handling the default case which prevents reaching the code for the deprecation. I opened a follow-up pull request to fix this, which can hopefully be merged before PHP 8.5 is released: https://github.com/php/php-src/pull/20172