Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102266 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22107 invoked from network); 14 Jun 2018 21:57:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jun 2018 21:57:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=chasepeeler@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=chasepeeler@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.68 as permitted sender) X-PHP-List-Original-Sender: chasepeeler@gmail.com X-Host-Fingerprint: 209.85.215.68 mail-lf0-f68.google.com Received: from [209.85.215.68] ([209.85.215.68:40510] helo=mail-lf0-f68.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 40/8E-29356-2B4E22B5 for ; Thu, 14 Jun 2018 17:57:08 -0400 Received: by mail-lf0-f68.google.com with SMTP id q11-v6so11701347lfc.7 for ; Thu, 14 Jun 2018 14:57:06 -0700 (PDT) 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=wg3PMItXUl9kMu2kb1EB35hnERiyBFYtN0CoDL4RHwU=; b=FLAixVjeLNyqMW4Uxw6fe4mKEtAkn/u/DA0FtC53vKdiGuHjFjIJNDV4CfMmOAzpsD nIklTILxQ86aogKQJz/sSc0ko/sgLcXMezFMzR/EfdaRhMJyLAueohAThqpMazKnHIeH 9X5tuAAlwOhimXnRjAGDxyNRh4lVU1dayDnZ4Lrc87qW9aHmxA5mL+JQArx985BxUwhm 64bHYK47mBuGg+3QsIgVWWZtAvq8cS/ioMisydWrgv+IkaNYiB/tuYc6SHOEr09IIrWT GcXH+mspkAuoZc6RntAZ1tgKVQ3RhLPaZll4OQb7BFfNaq+5CWBqA6G9Fyj/dl8nFNog XTbA== 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=wg3PMItXUl9kMu2kb1EB35hnERiyBFYtN0CoDL4RHwU=; b=nmYpe9w0S0ub88kWEm7L9LPyhA87SRIk2123WEy2K/7m/uRZukBu3MAz9ME4ASlW8U iGGWPGdMDfcjNqbcqzeyAfmTLKuP4p/jDrWxBuaRpf9u9fLX0vHr+n+hR+iDHMSoHk6T jSs/JZwqLF7ouSLgcve/7vftlQwCKxdckUkV+SYN29fvmmCagtCBm25w3HTPQ/Ju3cFL dr4d9lxCNcDnO1MKO5oJdOMrAOUcKBE+3rZNJPXy45aOwnW3z9CdVtDBYvPUGWTVNOMP +WFBpkWgjlSuDWCifNLjODlLlFfdpRQ4LBpsW+cOvZ9hEx/EtpCvA/Ehz8UUaDAKMZaQ pgwQ== X-Gm-Message-State: APt69E3bLF5V85W77pbIck2j5yHRm7EhNNP1e+XjnmGy3mgAP0HCjUOx kew6+3YJQRJ72V8EubvaFm9z0DNVNu+JddPnoXc= X-Google-Smtp-Source: ADUXVKJ8Y/AsSQ83VpxYBZuLmhjYGQW/vS9PM55td9CBk6tI4MSyP1ZwB2GdXANQB07IEbNMWTfBJI7pmNNxChIjTuk= X-Received: by 2002:a19:c004:: with SMTP id q4-v6mr6783459lff.16.1529013424125; Thu, 14 Jun 2018 14:57:04 -0700 (PDT) MIME-Version: 1.0 References: <20180614155730.2C8BC1A8027C@dd1730.kasserver.com> <53d1a1f6-10b8-3aec-c2ac-a005d6041f15@librelamp.com> In-Reply-To: Date: Thu, 14 Jun 2018 17:56:51 -0400 Message-ID: To: Rowan Collins Cc: Alice Wonder , PHP internals Content-Type: multipart/alternative; boundary="000000000000007f25056ea12e82" Subject: Re: [PHP-DEV] Strict switch statements From: chasepeeler@gmail.com (Chase Peeler) --000000000000007f25056ea12e82 Content-Type: text/plain; charset="UTF-8" On Thu, Jun 14, 2018 at 12:45 PM Rowan Collins wrote: > On 14 June 2018 at 17:16, Alice Wonder wrote: > > > > > Should declare(strict_types = 1) do that? > > > > I haven't tried, but I would think it should. > > > > No, it doesn't, and shouldn't. "strict_types" actually means > "non_coercive_scalar_type_hints"; it's a very specific feature, controlling > a specific set of situations, not a catch-all "strict mode" for anything > type-related. > > I suppose we could have a new directive that magically changed the default > for the "strict" parameter of array_search, et al. But if that converted > switch, would it also convert == itself? And then would we need a new > syntax for "opting out" and using the loose comparison? Would the resulting > confusion of people not seeing which mode a file was in be worth it? > > This is exactly why I think the word "strict" should be avoided at all > costs; it's just far too ambiguous. > > Regards, > -- > Rowan Collins > [IMSoP] > Here's an idea, that leaves the flexibility to use strict comparisons on a per case basis, but doesn't use the === syntax, which I don't like either. switch($a){ case true: //will match true, 1, etc... break; strict case false: //will not match anything except boolean FALSE //other stuff break; case false: //will match 0, null, etc.... break; } You could expand this further with a second parameter to the switch, as someone proposed above, that would put it in "strict" mode, and, allow a keyword to change things back to non-strict as needed: switch($a,true){ loose case true: //will match true, 1, etc... break; case false: //will not match anything except boolean FALSE //other stuff break; loose case false: //will match 0, null, etc.... break; } And, if it's in strict mode, you can still specify the strict keyword, and if it's in non-strict mode, you can still specify the loose keyword. Shouldn't even have to make them reserved words either, since they only have meaning inside a switch statement, when immediately before the word "case" -- -- Chase chasepeeler@gmail.com --000000000000007f25056ea12e82--