Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112352 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8897 invoked from network); 1 Dec 2020 20:03:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Dec 2020 20:03:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AB55E1804C0 for ; Tue, 1 Dec 2020 11:30:45 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 ; Tue, 1 Dec 2020 11:30:45 -0800 (PST) Received: by mail-lf1-f49.google.com with SMTP id l11so6736812lfg.0 for ; Tue, 01 Dec 2020 11:30:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=W53PW4fKo97u0/pt8ONXEWQMtCFEXP2HuLIIdDxEkLQ=; b=dbCiOZv3uX9FFZqjkPchz3Gsn/b0ZBtX/NWcBQAGFQqS0R3Y62XOXvxBO45L+MYXjI KwkvR2bhi/hFLiFfLu+z0Yhq4EIACk8riyps30J4wD7nlHPua1dvxyaYimOPWGQvFg4z HlWQotYo/tOh4kalc/2kdzmZWDj8alAyw7g29bU3fTEeUX7vfOUAfyWvU5OY1I9b5a4d tO1cu94OaDm7ukLDdIQYKlmu/CdIx+UXqM52NLwO2cTBDRybYzMo+rB6JkNYeZSX3Mcm AwQahNHrXJxEBDBbtYfn/KjiMGDhJANm4T0jBotepvsXRfF2ig6b+r6J76FPOSW0Wqew BcSg== 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=W53PW4fKo97u0/pt8ONXEWQMtCFEXP2HuLIIdDxEkLQ=; b=HerfSyF49OCjA3eCpIgcZMblVFcgzkt+WFeoN+kELqRp5KnP435bLBnu20S+BNxIQn awKOtb6VksvgIG+jvLSeOxbCdDPeHJygDsiBbtFZ19m6wruvNEBguSimH9iIUMH2kZmG FgmL06tD5Xf6KdKSpoEy/Snk+USHqQx0XpmUCPzgHmh7cWBwk191drZXgDxRuYgakup/ uJMZklz0XfKgXspHtsOOYzsJeClEQhrdqI7HDDsgZJ+BxiVP2gbIJabN9Mn0jH5G9lfv K3ZTnqa5kVc+9HloWbYYIHoQ6kGuZmfFa1Sqt8cGsnj8jZTrgwIZKAxDtZdr4gRKYurT QfgQ== X-Gm-Message-State: AOAM530BIEUqmmQ6SQLCtnhp1L21L4SemN8gmqaZGHoimc7ivdwtGECy zuyNsC3SDjZGBDS926FDxqDzByYqitcdJmBegDkBe7DPfDY= X-Google-Smtp-Source: ABdhPJwWQLtjNiXTxWuWQYgmcY+PwRxMNhI2gco+/6PIwFw7V2ZjtO90wHnN7vwpfQeITp/2gsD3ri+qfNp3ypEQDPQ= X-Received: by 2002:ac2:50d2:: with SMTP id h18mr1811627lfm.169.1606851043732; Tue, 01 Dec 2020 11:30:43 -0800 (PST) MIME-Version: 1.0 References: <5ba9d3db-7c4c-4929-ad22-65727141a52d@www.fastmail.com> In-Reply-To: <5ba9d3db-7c4c-4929-ad22-65727141a52d@www.fastmail.com> Date: Tue, 1 Dec 2020 20:30:27 +0100 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000ab30a105b56c297a" Subject: Re: [PHP-DEV] Strict switch From: nikita.ppv@gmail.com (Nikita Popov) --000000000000ab30a105b56c297a Content-Type: text/plain; charset="UTF-8" On Tue, Dec 1, 2020 at 7:57 PM Larry Garfield wrote: > On Mon, Nov 30, 2020, at 9:09 AM, Nikita Popov wrote: > > On Thu, Nov 26, 2020 at 5:39 PM David Rodrigues > > wrote: > > > > > Hello! > > > > > > With PHP 8 we have match(), that is a switch strict expression-like. > But > > > strict is not strict, and it could cause confusion because switch() and > > > match() are pretty similar. > > > > > > I believe that this has already been discussed, but it would be > interesting > > > to re-evaluate the possibility of a strict() with support for strict. > > > > > > In order not to generate BC, my suggestion is to attach a specific > keyword > > > for this purpose, or a similar alternative. > > > > > > (0) switch(8.0) { case '8.0'; return 'no'; case 8.0: return 'yes'; } > // no? > > > > > > (1) strict switch(8.0) { case '8.0'; return 'no'; case 8.0: return > 'yes'; } > > > // yes > > > (2) switch strict(8.0) { ... } // yes > > > (3a) switch(8.0, true) { ... } // yes > > > (3b) switch(8.0, strict: true) { ... } // yes (named argument) > > > > > > Or then in the "case": > > > > > > (4) switch(8.0) { strict case 8.0: ... } // yes > > > (5) switch(8.0) { case strict 8.0: ... } // yes > > > > > > Or allowing operators (this would be the most flexible way, as it would > > > allow for a number of other features): > > > > > > (6) switch(8.0) { case === 8.0: ... } // yes > > > > > > > > > > > > Atenciosamente, > > > David Rodrigues > > > > > > > I think the better direction here would be to improve match() such that > it > > can replace more of the current switch use cases. If match supported > block > > expressions, then most uses of switch() could use match() instead, and as > > such make use of the strict comparison semantics. Only switches that make > > use of non-trivial fallthrough behavior could not be easily expressed > using > > match. > > > > Nikita > > Disagree. switch is a procedural logic flow control. match is an > evaluation expression. Things like fallthrough do not belong there, as it > mushes expressions together in weird ways. match is lovely because its > logic flow is simple and predictable. We should keep that. > Sorry if the phrasing was unclear. I'm not suggesting to add fallthrough support. Fallthrough was mentioned as the one thing that match cannot and should not support by design. I'm referring to support for non-trivial expressions, aka blocks. Say, the ability to split up a long expression by using a meaningful temporary variable. Block support is sufficient to cover *most* switch use-cases, obviating the need to introduce a new switch variant. Regards, Nikita --000000000000ab30a105b56c297a--