Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109390 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78332 invoked from network); 28 Mar 2020 16:03:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Mar 2020 16:03:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 62B181804C4 for ; Sat, 28 Mar 2020 07:28:30 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-ua1-f68.google.com (mail-ua1-f68.google.com [209.85.222.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 28 Mar 2020 07:28:29 -0700 (PDT) Received: by mail-ua1-f68.google.com with SMTP id z7so232979uai.6 for ; Sat, 28 Mar 2020 07:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HngwPj+ctcS+kwJqwYchd64qgvQkNKNjenlcGwtxVAg=; b=pBwqaFU8JEalkI/w2Sk9/Yo4PA3wjh1l5c23yKvXRzC/F/kS94r0gvbVk/E5atoS1x 955emKYRCegqwPjUU+G+N0GnzAztKXxnpxjYTeD/KxThuObBxrJQ1bI5TU9uKT1Yf538 NTxZd9tSLvglIe/I9+7g9ryDTCN5Iikjx/n8FYaFuzpqCR542bJC1Tr1hOC5oFnvE1Db aBKKJhzBN8DcQKkP6LcdAd7RpaZnXTRh8exsNfPYANRBGE+rgldR4PSLV4XUZqm8fSQO Y8ThAKwguKwPf3YKFI+VU+3052uFi2ZzGOmX4/pSSA9/jqyfWL+9V729SUhtoVBobBoK xZdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HngwPj+ctcS+kwJqwYchd64qgvQkNKNjenlcGwtxVAg=; b=Q8JpajSJvEVAaIibu9TmezAgEX3VuNaqwkg9G28FZtt2HpxWSJyAaLQ/ARi2ZTRkPE FlF5v76c/AFIlyAgIBkxv1Zapl7VVqpqzJMzqyJHtHG+eU3mSwcxo/2lBkOKVccHo6JM tIkwS+ygjhc/2dmDsStuKcmH3IQ0YZbXJKXn9f1oBp63X2O3E4RLxKBDUz83nXLpkrXo n+09n9fuz8kVMtItrxpnG2u5RUrsWFWXQ50ZGo/w5Jn9QdY/iBNJQm2LyiwMCxZ5UwTs x3URHVoHj1xxJHV8DoNrTUb9rCMtZJGd0yRnp+lugKWEiFpEGi4HrVVZMMHWa7ehPnOI Zm3g== X-Gm-Message-State: AGi0PuYxbucXRD8brZKuqDEmnfh/18yZseUJ+79P4WP7/KTpTp/gNxCo oNJcSSLyjJzSYa3HxbjoP58I+KTYE3Fil1P810XdfA== X-Google-Smtp-Source: APiQypIvcblMJjtqYPHEbC7iJaLs8+oBOUSvW50TLpoVrIu7wFzBDYhZSZOTSKjLUonb43BpSVj00H7/9307RQ4g/OA= X-Received: by 2002:ab0:63c3:: with SMTP id i3mr2640674uap.127.1585405706476; Sat, 28 Mar 2020 07:28:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 28 Mar 2020 14:28:15 +0000 Message-ID: To: Ilija Tovilo Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC][DISCUSSION] switch expression From: Danack@basereality.com (Dan Ackroyd) On Sat, 28 Mar 2020 at 12:40, Ilija Tovilo wrote: > > Hi internals > > I'd like to move the RFC switch expression to "under discussion". It > tries to address some of the common issues with the switch statement > by introducing a new switch expression. > > https://wiki.php.net/rfc/switch_expression Hi Ilija, The switch statement is definitely something that has issues. However I think the RFC as written is not a good starting point. 1) The behaviour of switch with regards to type conversion is the biggest thing I care about. If the RFC isn't going to touch that, then it's way less interesting to me. 2) In general, I think that using the switch keyword with slightly different behaviour is not a good idea. Even if we had 'editions' in PHP, having subtly different behaviour is very confusing. A better approach would be to use a new keyword (maybe 'select') that has the correct behaviour from the start. 3) Fallthrough: "The fallthrough behavior can't reasonably be changed in the switch statement because it would break a lot of code. However this RFC porposes allowing multiple conditions per case so that the intention of running the same code can be expressed more clearly. " I don't think this is the right approach. Most new languages have the rules of: * each 'case' statement has an implicit break statement at the end of that case. * they provide an explicit 'fallthrough' keyword for where fall through is desired. In general I think there are lots of details that need to be thought through. I don't think this email list is a great place to work through all of those details. Email is not a great medium for this type of discussion in general, and causes a lot of noise for people who are not taking part in that work. Some of the people who are interested in working on how to implement generics in PHP have been doing that in a github repo https://github.com/PHPGenerics/php-generics-rfc/issues If you have the energy to work on this, please consider opening a similar repo as a place for people to discuss ideas and work through all the details, as that would be far more likely to have a productive discussion and produce the best possible RFC*. oh, and obviously link to that repo here so people can join that conversation. cheers Dan Ack * btw it might be worth thinking about pattern matching as well. Currently the below is supported, but is also horrific coding (imo) standard. function checkValue(int $x, bool $errorIfOverTen) { switch (true) { case $x < 5: return "too small\n"; case $x > 10 && $errorIfOverTen: return "value is over ten, which is not allowed.\n"; default: return "Ok\n"; } } echo checkValue(3, false); echo checkValue(11, false); echo checkValue(11, true); output is // too small // Ok // value is over ten, which is not allowed.