Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112304 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 62753 invoked from network); 26 Nov 2020 18:12:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 Nov 2020 18:12:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EE2F7180211 for ; Thu, 26 Nov 2020 09:38:31 -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=4.0 required=5.0 tests=BAYES_50, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f175.google.com (mail-lj1-f175.google.com [209.85.208.175]) (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 ; Thu, 26 Nov 2020 09:38:31 -0800 (PST) Received: by mail-lj1-f175.google.com with SMTP id 142so3153413ljj.10 for ; Thu, 26 Nov 2020 09:38:31 -0800 (PST) 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=HO+5877jW/Se1aHxFHtqNvJz5SRBcyBw3q6XH77XeVA=; b=I7kyhhSCgEgbbQbwWYgaaSjNFBZdJdG/OaySN29k+rIvt+mRPoi/spYypxeP3VSiDD h10TBMeWEBorkecQxayhrxbHopErjUXSSOe5RMwrVU+IZ3AwdIGF7i+YCH8q2J9NLXyd vhnjCuNncIcjBGyHCgQaESVD52b9yt24xSKEYY5ImlSEm/VhScZiGJiF7Asl+YxDTjRL GhWvlIP7zTpckcsWp4CXsYouvtH7OcRTYitCIHgJ/738IIxEMMf/Cz3M4KvMdh51V8vQ qPx0919kF3vIJZgCMyVoQOrJvtYoTxR1gLsw1oIja2Q6xP7Y6k9XtYHEC5+N6EisPJc0 7Iyg== X-Gm-Message-State: AOAM532wPJTOR7+euqsJ/gtdwHlJxr3RgRr4wKAH9DuegI+G09M+10NJ U4cQGLBhcFYiqFvErnu3dSL57xn2DV7Ns4CTt2jnJw== X-Google-Smtp-Source: ABdhPJz2plV3XR0y3t1MFQr3PxGzNgGvPC+ABlo/3knYGgRn2XfJfE7QYep7SdGySlFcbHhojwX5NEsaRwWdHuKQyw0= X-Received: by 2002:a05:651c:1109:: with SMTP id d9mr1735977ljo.289.1606412309611; Thu, 26 Nov 2020 09:38:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 26 Nov 2020 11:38:18 -0600 Message-ID: To: David Rodrigues Cc: PHP Internals Content-Type: multipart/alternative; boundary="00000000000013df7805b50603fe" Subject: Re: [PHP-DEV] Strict switch From: pollita@php.net (Sara Golemon) --00000000000013df7805b50603fe Content-Type: text/plain; charset="UTF-8" On Thu, Nov 26, 2020 at 10:39 AM David Rodrigues wrote: > 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 agree that PHP deserves the ability to do strict comparisons when requested and that match won't serve all of switch's use cases. This idea has come up a few times in the past, but I think we can perhaps get further with it now that the language is growing more strict-friendly. > (1) strict switch(8.0) { case '8.0'; return 'no'; case 8.0: return 'yes'; } > // yes > Introducing new keywords automatically has a higher bar to acceptance than not, so while this certainly reads well, we do have to consider the impact to existing code defining clases/functions named 'strict'. > (2) switch strict(8.0) { ... } // yes > (3a) switch(8.0, true) { ... } // yes > I'm not a fan of how either of these read. The first on wholly aesthetic grounds, the latter on opacity. The meaning of "true" is inobvious here. > (3b) switch(8.0, strict: true) { ... } // yes (named argument) > > This I like now that we have named arguments. It's a psuedo named argument, but I don't think that distinction matters too much from the userland perspective. Implementation might be a little on the ugly side though, so let's keep it in the maybe pile. > 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 > > These formats have been proposed previously, and I think they're the worst of the lot because now you have a comparison that is potentially sometimes strict and sometimes not. This has the highest potential for surprise. The main question I'd put to you is this: Are there other parts of the language where a strictness modifier would also make sense, or is it unique to `switch`. I suspect it's not, so list out those syntaxes and identify how the proposed options would translate to them. A general purpose winner may float itself to the top. -Sara --00000000000013df7805b50603fe--