Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109809 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13091 invoked from network); 23 Apr 2020 14:47:21 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Apr 2020 14:47:21 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2C9C31804E2 for ; Thu, 23 Apr 2020 06:19:15 -0700 (PDT) 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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) (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, 23 Apr 2020 06:19:14 -0700 (PDT) Received: by mail-yb1-f176.google.com with SMTP id o198so3105034ybg.10 for ; Thu, 23 Apr 2020 06:19:14 -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; bh=LuLLPsI4SBNHEMbDFVWrDcvpBVJ1983znHYldKTYkOM=; b=UVDGqJV3a2Df3njhtAn1kq6wqDTIkueeqWbRF5MtWAtpm5XojvGXh0if4bx5dEckXb jnxqptBKPFgSFJprvbBJ0j8gIfBkt09ySHzH7VNxtRpHijbOVuaEksGjgz9R3lmfevub hThuQOw7eh6iO3k6b+gxUY5986Q3TOuLr98O6sd3n7UOTC58EajmIcJHJ3mnOf5WUZs9 /pc0E077DYVnvSSb0nGpC/wyN9tAZuCQKZkLPNnCIwUHB9d24vm8Z+hHqkJW18dq817j K/ddZKNZq3CzauKI5fP0I3ZqWFwrYib0ldg30rhi2GKdqrHS3SGSVX6L5t6LSeXminC4 C4zg== 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; bh=LuLLPsI4SBNHEMbDFVWrDcvpBVJ1983znHYldKTYkOM=; b=eUrKTEPRQZdyn2wW2BSUzJEJ4U+N1RUPrj1ldP5VlO+Roh6NAmgAHjFOMKLDRlx8ya enoxWj7xULUExHhug9C7vOZ/+rAiGiauYaqPpVDAvpxoYWtssnbJNUzNctsSuc/wdIZR jPQGYLxNOisZIzEiI+u2Seh8IO3EI5G0c71kuXTfg+d+Q28VJu+gTa9P2OOE9urYtxkV rcWJCO20soV7YErfq3a3/z9xRSoyiyBsDLaB+KPjYdv73IRsKPwDWXvwVabu+jIIi1V5 HOS5FWlOvN3eOwOw5RcGX4dy0pPiyEDgBvl7GBTbxugMNDC5Ape1dcV0QkcRCfSNaYLS YBmA== X-Gm-Message-State: AGi0PubgSPyGlQeBKw260zc+D9lc7+9jXcC4Z4Ug3etPM1WE8sEh0uAz 2UCZzi1BDMZwjjuMasaLgO6fi8BhgO8RQB2/Rv4jTdFF X-Google-Smtp-Source: APiQypIdqzo6ug+Au01wav2SIvYHm1DSAIFp1fryhIxGD+HoRECxdtRKkAKk/sqcVPY3Zwl+OYlYNYEk/esbvhUcT5Y= X-Received: by 2002:a25:b8c1:: with SMTP id g1mr6785732ybm.411.1587647953437; Thu, 23 Apr 2020 06:19:13 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 23 Apr 2020 15:18:59 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Re: [DISCUSSION] Match expression From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Dan > I don't think PHP can guarantee to detect duplicate conditions This warning is only shown if duplication is guaranteed, namely when a jumptable is generated. Which also makes the check fairly cheap. > Would the duplicate condition* below be detected? No, as jumptables are only generated when the conditions are all integers or all strings. It's worth noting there are some cases that could be detected but aren't. For example: match ($x) { 1, 1 => { echo $x; } } This is because we don't generate a jumptable when there are less than 5 integer conditions. Because of this inconsistency I'm not sure if we should just remove the warning. As you mentioned, it could be intentional in some cases. Tyson also mentioned that some constants are platform dependent which would make it warn on some platforms but not on others. > Are the match conditions guaranteed to be called in order that they > are defined? I'm guessing yes, but it doesn't appear to be mentioned. They are, yes. The behavior here should be equivalent to the switch. It wouldn't hurt mentioning that in the RFC. > I would prefer having an explicit fall-through statement, for the > relatively rare cases when fall-through is needed. Is there a strong > reason to not add it now? I wouldn't call it a strong reason but we'd have to be more careful with fallthrough when we implement pattern matching. match ($x) { let $y @ 10..<20 => { fallthrough; }, let $z @ 0..<10 => { // Pattern $z was never bound } } Other than that, I just don't think it's awfully useful but that's of course a matter of opinion. But there's nothing directly stopping us from adding it. For me personally it's not a priority. > Is there any protection against people doing odd stuff with > references*, or is that their own problem if they choose to do that? We have some tests for references, we couldn't discover any weird or surprising behavior (although we could definitely use more tests here). Ilija