Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112318 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48579 invoked from network); 30 Nov 2020 15:42:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Nov 2020 15:42:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4B25E18050B for ; Mon, 30 Nov 2020 07:10:00 -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-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (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 ; Mon, 30 Nov 2020 07:09:59 -0800 (PST) Received: by mail-lf1-f44.google.com with SMTP id t6so22234837lfl.13 for ; Mon, 30 Nov 2020 07:09:59 -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=JwCEgrXAFPmcA1lKo3QDzuk153JIePbdi1Uv8aQitsQ=; b=elcehtfZWmZCUeTJ/cJIoJ8M6fwV8YY+AAj6YPaPVkzMNmQh3Ffbb/DWT7MmsMQW6o rOHlZfts+Vm3VlZiU6LTFCf61C4VafpD8P9rgwiS4dJNv21WQKupK/I9s8J7KhgQ727n cfRNgumndF4n4ZODuha1aGBTmuNry9iTVKO+3jIo0Cn6W2XOPVgl9CRRULir8F4IeCoW sc3YYDuZYHMBKxWXxYc+PvhQdrUT4/4bQrnBy7NEWdvMfHVAS//IALeq1yFdjghI0hCO mSW9SxO4KVY3T/A3KoHdO1Chqgt6L7jTu3A2f3GFZn1TUQGPeKgTxlrmEBAqz8icCiNG m5Fw== 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=JwCEgrXAFPmcA1lKo3QDzuk153JIePbdi1Uv8aQitsQ=; b=Odt/+rbJbMvTt7cWK6DZIhGng3JxRDi32Xng+rJHAcT56yKk3ZnJXeW/01vGs4eDvW b/5y/jYhejH4l+ag/FBZ5JiTaABXqIOtsrT04qEayDDLrCaCjw4i8/QY/N6JZ3qf4na4 aTyRacG8P1X9/qQuWpmxX7sSPHuhBJE0TK9OVRtwZEWcKOMtlVRfLZmM0aydRQ0DDl8n xoMIGqi6wZZi92UOJynGShWSXBAkH+lUlkPcZN8Y8xSuBDHtjSEE3yhDGnN8+I9TurLS mzZ/I2ZGKYXiICY29oLWK2ICiPhxwLRrDKRvskSLePJMqUqdcv/DOubClLdWLq6gJP4j TPyQ== X-Gm-Message-State: AOAM531ROgFM4gJfnIdKUU5u4Cn6OWVIZQpABHtqKui/B4bDNWp3/lxG WxYfkvuX8EU7fkOZjL9B579wnB9uwNjssJ9AEmU= X-Google-Smtp-Source: ABdhPJxU9nio8USYs6Wn8wsgrYRdwHHFfraFDJERbZVqhQ6Y5EtXlEJZgqcg7a8cObs5//QPgnfhTzDkcF/Lyq/LSwU= X-Received: by 2002:ac2:5f56:: with SMTP id 22mr10189214lfz.439.1606748997285; Mon, 30 Nov 2020 07:09:57 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 30 Nov 2020 16:09:41 +0100 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000039fa7105b55467f9" Subject: Re: [PHP-DEV] Strict switch From: nikita.ppv@gmail.com (Nikita Popov) --00000000000039fa7105b55467f9 Content-Type: text/plain; charset="UTF-8" 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 --00000000000039fa7105b55467f9--