Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109296 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25216 invoked from network); 25 Mar 2020 17:22:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Mar 2020 17:22:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EECEA1804E6 for ; Wed, 25 Mar 2020 08:46:44 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 25 Mar 2020 08:46:44 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id C22C75C02EC for ; Wed, 25 Mar 2020 11:46:43 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Wed, 25 Mar 2020 11:46:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=T8A+GA wOu8ywe7LGApI3YVZGU8+Iz0igVTxLKtTZZbM=; b=uWDJDr6lxma0AesuIk+BPB RiPvo489PpO1wlZvHQJuw7nhVdrSGKEbkY+UBcKVOSY0Sw/6qvyk25cwch0Im5Nx TEOtX19/Ffd9CPTK4ovUeB2sg5uEkLbH+X1GSt2NT01GdT6UE1Ma7cZKJT1ewnW+ B+ruY5V+FMVWz5eGT9KlwjGfF8WMXshInk8GGrr9YPrHjx922pjHEfT0231Y1+Fk 2SGHHhgo4YxKwsW/kfi1qknfhRts+DztsS5QHRieqSF82VyETy021aGW/mxZaZ/C 6R66OODZ4dqOyWl6lWPu65SC9fvnvc7fJDzlobybkYQXpK0ponBkaA6DqUV/cN5w == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudehgedgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehl rghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 3EB6A14200A2; Wed, 25 Mar 2020 11:46:43 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-1021-g152deaf-fmstable-20200319v1 Mime-Version: 1.0 Message-ID: In-Reply-To: <2E98378A-605D-40ED-898C-6ABBFBD091B9@me.com> References: <047092C7-84FB-42AB-8084-7B83F76F55C1@me.com> <4513B88E-CA5B-4DF2-94C8-242BEE54ADCC@me.com> <767910ef-d27b-404c-9ad1-037105c69d12@www.fastmail.com> <2E98378A-605D-40ED-898C-6ABBFBD091B9@me.com> Date: Wed, 25 Mar 2020 10:46:22 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] switch expression From: larry@garfieldtech.com ("Larry Garfield") On Wed, Mar 25, 2020, at 10:29 AM, Ilija Tovilo wrote: > Thanks for your feedback, Larry! > > > One possible improvement to either version is allowing an expression on the left side. That is, rather than doing an equality match, do a boolean match. > > This is how Rust does it: > > ```rust > let x = match ... { > Some(y) if y < 5 => ... > } > ``` > > In other words, you can add an additional guard to each case that > excepts any expression. We don't really benefit a lot from that since > we don't have pattern matching. I don't think this would add any > significant benefit over: > > ```php > $x = true switch { > $x !== null && $x < 5 => ... > } > ``` Good point, I'd forgotten about that potential trick. So as long as an expression is allowed on the left, rather than just a literal, which is then == compared against the provided value, that should be "good enough" for most use cases. The implementation should include some tests to make sure that works properly, but I'm happy with the resulting syntax. So then the net result is: $var = switch($val) { case expr1 => expr2; } Where $val gets compared against the result of each expr1, and if true then $var is set to expr2. Endorse. --Larry Garfield