Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102254 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74200 invoked from network); 14 Jun 2018 09:21:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jun 2018 09:21:30 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.65 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.65 mail-wm0-f65.google.com Received: from [74.125.82.65] ([74.125.82.65:56022] helo=mail-wm0-f65.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CC/A8-29356-993322B5 for ; Thu, 14 Jun 2018 05:21:29 -0400 Received: by mail-wm0-f65.google.com with SMTP id v16-v6so9290204wmh.5 for ; Thu, 14 Jun 2018 02:21:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Mmd497bG0nLzYMrY5hretsgICxF3Kxj/l0icR3CAb3I=; b=Na+NlSCaWX6ImIqYJLZQ9hUMgOrplG7zs/+3Fl9DTb4hI9hJFcLU5rPLVdgUQb1j6K F6BDla2SuUJEk7xfjdXsFwowtt3RnQDhuV0R0F+pNkRWx97Npqdc2vtcK5EQ3+c/72wJ WDBQiUwXzfms+lhiY//L/4fNEQwpwBJO9sqyVEwUKPl+4N/Ba/z3mrhofmWhWlDzEgJx CGzLEWumNnjF9jrk91eqvsk87m9MhPC0r0VUgnStmz62Wgg4lPOcYERTrulg6U04uYkM 9xZ02W3+388wRVrscyevU85TatWedNiR6z/OODVw9WDLswYp+iY6GY9xYnkBoiLR4MJa s13Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Mmd497bG0nLzYMrY5hretsgICxF3Kxj/l0icR3CAb3I=; b=qazsrTMY3zD78R/i95e7LO3wTUF+JMwH4jUoG8olTTTeQLNS/GObzC6lWw3D09uRPM EF89W+ayEDFYLaEnWyzHY/vpByh9KfCuO++BjLKTptVTqNqNs714iYhJB0I0g7u/QNny Sb61DWXyzjsZMLFX1Z1waGYH/LAcOLoCSNzb4PLdvysU2oJ/VRLevYvJRh1M6CcDtMSN brkig1JStsX+UH8lNDfuxb8CDjmkuAgp6N5Pex9MPLic0jUol5RyAsp0LoFOQVF/dZhJ 6KbNPTdXFdIoyG3aN1Pexd4vDQv+KLih13fZrUmMYyzeKA2AcVQN4i6G0Hww4THdbJ5s 4TSA== X-Gm-Message-State: APt69E3wRhsmCeAYBxvzIFa1ST1v88kbkSMeA79f23OHAn0ufBDme/9l Yr2CIQO/KNdmlenBPlbaX3W0TfuWRQ59K5gc2pg= X-Google-Smtp-Source: ADUXVKIcnN5WKL6QHUdldqDBd9wJMphs4rq15JeMt7Rw5H7D0y3lsZt/BXVcvdHiQ7J1EvODHbMJaUGSiyp/QcdXV9k= X-Received: by 2002:a50:9622:: with SMTP id y31-v6mr1998947eda.32.1528968086448; Thu, 14 Jun 2018 02:21:26 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a50:8d55:0:0:0:0:0 with HTTP; Thu, 14 Jun 2018 02:21:25 -0700 (PDT) In-Reply-To: References: Date: Thu, 14 Jun 2018 10:21:25 +0100 Message-ID: To: Nikita Popov Cc: Sara Golemon , PHP internals Content-Type: multipart/alternative; boundary="000000000000aa6d7e056e969f92" Subject: Re: [PHP-DEV] Strict switch statements From: rowan.collins@gmail.com (Rowan Collins) --000000000000aa6d7e056e969f92 Content-Type: text/plain; charset="UTF-8" On 14 June 2018 at 09:35, Nikita Popov wrote: > On Thu, Jun 14, 2018 at 6:53 AM, Sara Golemon wrote: > > > Just for casual discussion at this point: > > https://github.com/php/php-src/pull/3297 > > > > switch ($a) { > > case FOO: > > // Works exactly as current behavior. > > break; > > case == FOO: > > // Nearly identical, though not using the ZEND_CASE optimization. > > // Can probably make this equivalent to `case FOO`, but it felt > > like an interesting direction. > > break; > > case === FOO: > > // Only triggers if `$a === FOO`, no type juggling > > break; > > } > > > > Love it? Hate it? See obvious flaws? The implementation is just a > > rushed proof of concept, not something I've labored over, it may well > > have bugs. Certainly wouldn't target anything earlier than 7.4, if at > > all. > > > > I like the general idea here (switch with strict type comparison), but not > super fond of the particular syntax and implementation. > > I think if people want to use strict matching, they'll quite likely want to > have it on all cases. Something like "strict switch ($expr) {}" or "switch > strict ($expr) {}" or "switch (strict $expr) {}" or "switch ($expr) strict > {}" or "switch ($expr) { strict; }" or whatever would be preferable in that > case. > For ages, I've had an idea along these lines kicking around. Like Nikita, I was assuming that all branches would want strict comparison or none, so was thinking of putting the operator at the top, something like "switch ($expr) use (===)". I figured it could then be extended so the "===" could be substituted for any binary operator; for instance, you could match values into ranges with "switch ($score) use (>=)". That said, I can see an attraction in a form with the operator on the branch, if operators other than "==" and "===" are supported; for the range example, it might be handy to have cases for ">= 50", "> 0", and "=== 0". I prefer reusing "===" in some way over the word "strict", even if no other operators are supported, because "strict" could mean a number of things - "strictly no fall-throughs", for instance - and I think that could cause confusion (people already expect "strict types" to mean more than it does). Regards, -- Rowan Collins [IMSoP] --000000000000aa6d7e056e969f92--