LWN: Comments on "The winding road to PHP 8's match expression" https://lwn.net/Articles/830206/ This is a special feed containing comments posted to the individual LWN article titled "The winding road to PHP 8's match expression". en-us Wed, 03 Sep 2025 15:16:11 +0000 Wed, 03 Sep 2025 15:16:11 +0000 https://www.rssboard.org/rss-specification lwn@lwn.net The winding road to PHP 8's match expression https://lwn.net/Articles/830813/ https://lwn.net/Articles/830813/ hholzgra <div class="FormattedComment"> In slightly related news:<br> <p> This brings back memories of my never implemented plan to have switch/case with an optional comparison function parameter ... e.g.:<br> <p> switch($filename, &quot;fnmatch&quot;) {<br> case &quot;*.gif&quot;: ...; break;<br> case &quot;*.txt&quot;: ...; break;<br> default: /* unknown file extension */ break;<br> }<br> <p> </div> Mon, 07 Sep 2020 09:51:27 +0000 The winding road to PHP 8's match expression https://lwn.net/Articles/830659/ https://lwn.net/Articles/830659/ mathstuf <div class="FormattedComment"> There are indeed discussions about pattern matching in C++ (using `match`). It is aiming for C++23. However, C++&#x27;s `switch` doesn&#x27;t have anything new over C&#x27;s `switch`.<br> </div> Fri, 04 Sep 2020 16:08:49 +0000 The winding road to PHP 8's match expression https://lwn.net/Articles/830530/ https://lwn.net/Articles/830530/ jezuch <div class="FormattedComment"> Match expressions are in vogue right now it seems... Two articles about match in Python and in PHP next to each other - coincidence? ;) And Java also recently overhauled the switch thingie to make it optionally an expression and to eliminate fallthrough... This makes me curious, is a similar overhaul one of the myriad changes that the C++ committee made to the language?<br> </div> Thu, 03 Sep 2020 16:12:16 +0000 The winding road to PHP 8's match expression https://lwn.net/Articles/830454/ https://lwn.net/Articles/830454/ Henning <div class="FormattedComment"> I do rarely write PHP, but quite often C so my perception is based on that. I mainly use fallthrough for two things; grouping and parts that share common code-tails.<br> <p> With grouping I mean:<br> <p> switch(var): {<br> case 1: <br> case 2: foo(); break;<br> case 3: <br> case 4: bar(); break;<br> default: foobar();<br> }<br> <p> And parts that share common code-tails:<br> <p> switch(var): {<br> case 1: fn1();<br> case 2: <br> case 3: fn2(); break;<br> case 4: fn3(); break;<br> default: fn4();<br> }<br> <p> In the grouping part, there are three groups (1,2 and 3,4 and default) and in parts there is sharing between 1,2 and 3.<br> <p> Both patterns seems to come up from time to time and the match statement seems to handle grouping but not code sharing common tail-parts. But I guess gotos are still available in those cases where one wants to deal with these situations.<br> </div> Thu, 03 Sep 2020 00:37:08 +0000 The winding road to PHP 8's match expression https://lwn.net/Articles/830450/ https://lwn.net/Articles/830450/ mjg59 <div class="FormattedComment"> &quot;i want everything on a silver plate and stuff i dont know about is someone else´s fault and thefor bad design&quot;<br> <p> What we want is code that doesn&#x27;t have bugs. All the evidence suggests that the number of people who can write code that doesn&#x27;t contain bugs is extremely small, which means designing languages such that it&#x27;s harder to write bugs is a reasonable choice.<br> </div> Wed, 02 Sep 2020 22:56:55 +0000 The winding road to PHP 8's match expression https://lwn.net/Articles/830446/ https://lwn.net/Articles/830446/ professor <div class="FormattedComment"> You are perhaps right in a modern sense indeed.. Not everyone is like you though.<br> <p> This part i dont understand at all..<br> <p> &quot;Sure, Duff&#x27;s device is cool and all, but I&#x27;ve written one maybe once? Seen it only a few other times? Making it have a few more keyword instances would have been fine (especially since your indentation is already all kinds of whack most of the time, doing `fallthrough; case …` would probably have worked).&quot;<br> <p> <p> </div> Wed, 02 Sep 2020 22:29:41 +0000 The winding road to PHP 8's match expression https://lwn.net/Articles/830443/ https://lwn.net/Articles/830443/ mathstuf <div class="FormattedComment"> <font class="QuotedText">&gt; Yes, because I know when i want the behaviour!</font><br> <p> This mentality works for solo projects (and even then, more towards the one-off end of things). In my experience, having such sharp tools laying around with opt-in safety mechanisms make code review and later maintenance much harder. An explicit `fallthrough;` statement would have been a better solution rather than `break;`. Why? I find fallthrough to be the rarer case. Sure, Duff&#x27;s device is cool and all, but I&#x27;ve written one maybe once? Seen it only a few other times? Making it have a few more keyword instances would have been fine (especially since your indentation is already all kinds of whack most of the time, doing `fallthrough; case …` would probably have worked).<br> <p> <font class="QuotedText">&gt; &quot;i want everything on a silver plate and stuff i dont know about is someone else´s fault and thefor bad design&quot; is just weird</font><br> <p> I know about it and I even use it sometimes. I still comment when I explicitly mean for fallthrough to happen because I&#x27;m not the only one working on the code in question (even if another person isn&#x27;t, years-later me might have to figure out what the code in question is doing anyways).<br> </div> Wed, 02 Sep 2020 21:41:34 +0000 The winding road to PHP 8's match expression https://lwn.net/Articles/830438/ https://lwn.net/Articles/830438/ professor <div class="FormattedComment"> Yes, because I know when i want the behaviour! PHP is, in my opinon, a powerful extension for C.<br> If i want a break i would put it there and if not i would not.. Todays (-fifteen years) &quot;i want everything on a silver plate and stuff i dont know about is someone else´s fault and thefor bad design&quot; is just weird.. PHP have always been what it is according to the manual (which is one of the best) but if you dont want to read it and dont know what you are doing you just dont know.. even if this is &quot;crap&quot; it made it possible to create some awesome (first) results without knowing anything (which made it great but also is the black sheep nowadays).<br> <p> yes, i love PHP :)<br> </div> Wed, 02 Sep 2020 20:10:23 +0000 The winding road to PHP 8's match expression https://lwn.net/Articles/830431/ https://lwn.net/Articles/830431/ mathstuf <div class="FormattedComment"> Maybe better wording would be &quot;when I intend it to happen, it is useful&quot;? That&#x27;s my experience with it in C. There have been numerous times that I&#x27;ve been disappointed to have to add a missed `break;` in a switch statement (C, but that&#x27;s where PHP got its idea for switch; if C didn&#x27;t have it, I really doubt PHP would have fallthrough).<br> </div> Wed, 02 Sep 2020 18:50:51 +0000 The winding road to PHP 8's match expression https://lwn.net/Articles/830424/ https://lwn.net/Articles/830424/ professor <div class="FormattedComment"> well.. &#x27;often&#x27; was maybe to exaggregated.. but when it happens i like it..<br> </div> Wed, 02 Sep 2020 17:59:30 +0000 The winding road to PHP 8's match expression https://lwn.net/Articles/830423/ https://lwn.net/Articles/830423/ professor I often use the "matches falling through to the next case (if no break/continue)" -functionality in PHP switch.. It is one of its better features in my opinion, lucky me they create some other function for their modern stuff.<br/> <br/> What i could have wished for in the old days is that continue behaved differently in a switch-statement and also that better type checking would have been possible with === (in some way) but, as always, if you know PHP you still know how to use it safely.<br/> Wed, 02 Sep 2020 17:49:03 +0000