Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112349 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 2379 invoked from network); 1 Dec 2020 19:30:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Dec 2020 19:30:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 41FCA1804D4 for ; Tue, 1 Dec 2020 10:57:38 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 1 Dec 2020 10:57:37 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 90AA110B9 for ; Tue, 1 Dec 2020 13:57:36 -0500 (EST) Received: from imap26 ([10.202.2.76]) by compute4.internal (MEProxy); Tue, 01 Dec 2020 13:57:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=TazSYX mHd+aPwdCfMRta2HTkb4Poyb7o8gYLZXNlWdU=; b=GqxxfEub5GF3Z9mzXm9xpj x9LtnWPqMqvp9HmuPSUzukoyQ36uMVE7i/T/PS4wYpjm+wpYoOdATlT+ltY/ZTzq mulgPZNkSwHwxa5fLj3XA3Wjsy7pmU0dB/OBH6/Xw7qVv28FuG5RBBJqFrbQSauN H0Hw8QrS5hioqJYmyESg4TgwwYA5FnKhYkak1SoNUGUYwSH089Vgi8ysDNRtl7Fc 3DRqe9OmKngh5hZEJMwkH5fOXMExQxvhce5vVqcoVBWaN5STQfVl+YckUgsFpd1/ ub0EXvZt2PDDyMauHXn4skUCzFso+8CrqmSNsGWZ5LCWGcUy++NIfifNiPwpxjOw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeivddguddvudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefg ffekudevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 8794B14200A2; Tue, 1 Dec 2020 13:57:35 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-622-g4a97c0b-fm-20201115.001-g4a97c0b3 Mime-Version: 1.0 Message-ID: <5ba9d3db-7c4c-4929-ad22-65727141a52d@www.fastmail.com> In-Reply-To: References: Date: Tue, 01 Dec 2020 12:57:13 -0600 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Strict switch From: larry@garfieldtech.com ("Larry Garfield") 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. --Larry Garfield