Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109807 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97164 invoked from network); 23 Apr 2020 13:11:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Apr 2020 13:11:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 92A801804B4 for ; Thu, 23 Apr 2020 04:43:47 -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=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE 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-ua1-f41.google.com (mail-ua1-f41.google.com [209.85.222.41]) (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 04:43:46 -0700 (PDT) Received: by mail-ua1-f41.google.com with SMTP id 36so1248998uaf.9 for ; Thu, 23 Apr 2020 04:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=VmPSANwG992WdP6pQ77NrwtnYTRJE8jx5mCKqvL5/GQ=; b=rCtrjvDPhxLJmimsjHnrWFOc+xJlG+Ig4YCqVWk2iK2EDd+vvLByNTtvk+bgA1GpOq lrLtl82b2ovMm05AHJAV8YSgYzUlBPBlkgL9284eYza5VpgFpE3Wd5a3v+UHDQw7tVqf k3AptlFxWwCDDBxshF/y6icLZIM/v9EtLvi/cg2NztGB0R57k9/kSGl18XfV0xlMEmsH yvG/14Ccn3/rs0YtwnxPFGoO5rs+6vFZfMd78uH+tNI/7sYtw42VJNvfnMzE0HpkIefd eqR+nSuRerC9JnvxbF/drGneDXrC38OIcBSU1GZTnUz0jkUHiacJZck5co0igRiyZ/2m gUUQ== 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=VmPSANwG992WdP6pQ77NrwtnYTRJE8jx5mCKqvL5/GQ=; b=qusCp9/I6GlNvurF98IpNAHnZTnl4QC8SC+B0nrsDnIFO53ySw/LtW7JzUfeAuGN7o czx0PCwiH+08sVDx9DU7ADwdTVgKC6EL7auDVQQd//YEhoEIA1/jA3PLsgvomxXmS+6y zUZneh2h4Ci1BGawLSyIZ42yFuAk1SXJz1JTVyyyT6NuLcyaTxVIwSk5J3Jbijpy0BXk pqLJqAja5uddvJTIxSOa5NyzCLLEH6wFNgT5deqZgQajyZ5k7qoo6eYNkCQklfn/OuyF SmzBFXzrHwe9w5O22NimQbCpoGhXMt6EQrAcltvIHaDwDIMTqWOMTznzQgL+zd92GJEE TKAg== X-Gm-Message-State: AGi0Puam27w7OCS94bbaWCBf9wPciapH8zxNcBkg4RcmfheSipQa2Tc/ vISVfz+BtDm9Heya7Z7ms7mpRUSMdg2ciy75c4mS/A== X-Google-Smtp-Source: APiQypI+Pwv/uo6ksgZaP9IVWdI1Md59+NnRMe9/leWwkq0AI+tWnenvGwyc8xOwd9KHAI6+pAAZC8oIu/j7+A+ZWAQ= X-Received: by 2002:a9f:2acd:: with SMTP id d13mr2613840uaj.24.1587642223782; Thu, 23 Apr 2020 04:43:43 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 23 Apr 2020 12:43:32 +0100 Message-ID: To: Ilija Tovilo Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Re: [DISCUSSION] Match expression From: Danack@basereality.com (Dan Ackroyd) On Mon, 20 Apr 2020 at 19:20, Ilija Tovilo wrote: > Just a heads up, I'd like to start the voting on the match expression > RFC in a couple of days. > The jury is still out on: > > <*multiple issues> > > If you have anything new to add to the discussion, this is your chance! > On Mon, 20 Apr 2020 at 19:20, Ilija Tovilo wrote: > Just a heads up, I'd like to start the voting on the match expression > RFC in a couple of days. > The jury is still out on: > > <*multiple issues> > > If you have anything new to add to the discussion, this is your chance! > In the tests there is one test for "Test warning on duplicate match conditions". I can't see that mentioned in the RFC. Is that going to be applied? To me, that sounds more like something that should be done at a static analysis level as: * Sometimes it's convenient to have redundant match conditions. e.g. within generated code, as otherwise you would have to eliminate duplicate conditions. * I don't think PHP can guarantee to detect duplicate conditions. Would the duplicate condition* below be detected? 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. 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? Is there any protection against people doing odd stuff with references*, or is that their own problem if they choose to do that? cheers Dan Ack //* Duplicate condition function in_range(int $value, int $min, int $max) { if ($value < $min) {return $false;} if ($value > $max) {return $false;} return true; } $value = rand(5, 20); match (true) { in_range($value, 10, 15) => 'in range', in_range($value, 10, 15) => 'in range', default => 'out of range' } //* odd stuff with references function why_do_this(&$value) { $oldValue = $value; $value = rand(0, 10); if ($oldValue < $newValue) { return true; } return false; } $value = rand(5, 20); match ($value) { why_do_this($value) => 'foo', why_do_this($value) => 'bar', 7 => 'lucky number' default => 'not sure why anyone would do this' }