Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102253 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70879 invoked from network); 14 Jun 2018 08:35:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jun 2018 08:35:53 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.67 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.214.67 mail-it0-f67.google.com Received: from [209.85.214.67] ([209.85.214.67:36785] helo=mail-it0-f67.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F3/38-29356-8E8222B5 for ; Thu, 14 Jun 2018 04:35:52 -0400 Received: by mail-it0-f67.google.com with SMTP id j135-v6so7597344itj.1 for ; Thu, 14 Jun 2018 01:35:52 -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=0FDQiaJxGbHLFW5F545MpnXUmmEM3neXiAkYdSOnrDs=; b=dwOFp97OeIuABmXqY/oXxcISdNi8ApKF/QVIt/ys6ojT3htGpbtlRdJXI76JGiX5Us CSKBgngXDCKKI4UE1h4oU7EknFFduAz3L/Ycy9qSozKZfBeuly8MLqXzFS4P4cu2iwPV hb/4GpUm11RZJO1F8QrMpFHt3cih0zagYS+vZZUQfW42V3A+mDZackTBlDabsiNSmFEj 0YtVfpKKXoi16tT6S2yuGX0M3TZiyho2rIylSk99gM08sCBknlhJ4/3VjVOS66mZxKmY JpeWTHjLbOPD11Yvr4P5BB2JdDNwmtchprysO/HAsM8+Qfe8z04YA3w97MzByGuOnQic T3wA== 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=0FDQiaJxGbHLFW5F545MpnXUmmEM3neXiAkYdSOnrDs=; b=LgH0XpPBGSJl4q3WkZfgqlK8Z+zgt5NFM+zJ4hcU7YzpwuaC0jzD849fYtr9xkKqRo Ynjuxq/5RmbORlmyPaCrduEF3UeJpasAo2aNmZam1w4J7PYJrhfpn0lMyZgbOGUzztwF 63FXVQvHFhJj9qb9QqxwKd7murwyvYIkEMYpwPN4feA4u70PcEAni3AkFC7o5JsO/ajW IQ0VpwuL0zdMVhgUL6zks5QZp93EQuNycR3iCKiJV7KZzzIFQsDEUTnRSbzgcqPefpqG Yp/ME+ytoJ4dOVdv2jyK6XPn9DtHEVY1Y3hOO8mD5M6V/q39SHGDJSSOmvn8lBv213we eApA== X-Gm-Message-State: APt69E0Ho94hBgq5MduW7q1BPfwjfw08yj5xHHqZVnCI5bOdshxnjxwY Klri1GVQ/gcvnThUG7v1cC7uN5m3PnMALVar3fE= X-Google-Smtp-Source: ADUXVKLy0WJJvnYgZlwSlI3xtRgNus+8VV5KjqDixHGXDo9A2Nw/TUoP4qEZ0ahm8xPtmSL/1vFQZQtdj7S0w+v6pKU= X-Received: by 2002:a02:7157:: with SMTP id n23-v6mr565933jaf.94.1528965349985; Thu, 14 Jun 2018 01:35:49 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:acc5:0:0:0:0:0 with HTTP; Thu, 14 Jun 2018 01:35:49 -0700 (PDT) In-Reply-To: References: Date: Thu, 14 Jun 2018 10:35:49 +0200 Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000008f540d056e95fc3c" Subject: Re: [PHP-DEV] Strict switch statements From: nikita.ppv@gmail.com (Nikita Popov) --0000000000008f540d056e95fc3c Content-Type: text/plain; charset="UTF-8" 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. Additionally, switch has the issue of fall-through behavior, which is somewhat unexpected and error prone to many people. It might make sense to introduce an entirely new "match" statement that conforms a bit more with how switch-like strictures are implemented nowadays. That is, something like match ($expr) { "foo" => {...}, "bar" | "baz" => {...}, } or similar. This might need some more design work to ensure forward compatibility with potential future algebraic datatypes etc. Nikita --0000000000008f540d056e95fc3c--