Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109432 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93872 invoked from network); 29 Mar 2020 23:25:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Mar 2020 23:25:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 21E181801FD for ; Sun, 29 Mar 2020 14:50:48 -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,SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) (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 ; Sun, 29 Mar 2020 14:50:47 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 17B826FB for ; Sun, 29 Mar 2020 17:50:46 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Sun, 29 Mar 2020 17:50:46 -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=ye8VFQ Ukf75BRTG06jmkMi9SEOtERthIMVU8lGcdWzY=; b=hB+L+CdLgnFSKI2735wmY+ fbBDNrM53/QjhUWbE+n8jfssPzL84pHR7wbNszjgMjnN1Q+O2vxifaZ9b+lo0PSX XVqIgGJuXLroK+YoAIC8ug0wKa0RX5z3rcuiHUyQ19BDFPQygcRV/jzl+7mSxGxb daoNpMDQ6ztHPtcP9o0LJ9NjJ4k7nmcIKV2M+5qq584GQJy568X25OOGw829TURf EXtUdO4Y9ArcM5CFC/r0Q4hg/IqoE4d3RA2hP0Lyfgq96u7ubQCX1XmPFg1FO22E 2fdKUUN1AII3h4Lep6HE7axpkVAJJWJbNAOqqII74AtLLcbfJHTfwTqWmAjnU/xw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrudeigedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehl rghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 29B8D14200A2; Sun, 29 Mar 2020 17:50:45 -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: References: <047092C7-84FB-42AB-8084-7B83F76F55C1@me.com> <026AF97E-ED0C-411C-8942-7DA7CC9705DB@me.com> <34ce624e-7d00-4f63-2c4f-da125deb65b8@gmail.com> Date: Sun, 29 Mar 2020 16:50:24 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] [RFC] switch expression From: larry@garfieldtech.com ("Larry Garfield") On Sun, Mar 29, 2020, at 4:04 PM, Ilija Tovilo wrote: > > Having two syntaxes for one keyword is not a good idea, > > We're already doing that. What about classes vs anonymous objects? > Functions vs closures? > They're using the same keywords. There's no confusion. > > Ilija There's subtle and important differences there. An anonymous function is still a function, in that it is a routine that takes input and produces output. A closure is, technically, an anonymous function that has imported variables from its parent scope. Anonymous classes (not anonymous objects) are implemented as, legitimately, classes; they just have an arbitrary internal name. The object that results can be used exactly like any other object, by design. I don't believe that's the case here, however. `switch` is a language construct for a *statement*, which branches the flow of control of the program. What you're proposing is a language construct for an *expression*, which evaluates depending on internal logic to a different value. Those are sufficiently distinct that I agree they should have distinct keywords. Plus, the internal syntax is non-trivial to switch back and forth between (break vs not, etc.), so it is misleading for people to present them as two slight variants on the same thing; they're really quite distinct, and that's OK. My recommendation would be to just borrow Rust's keyword: $result = match ($var) { $expression => $expression; $expression => $expression; $expression => $expression; default => $expression; } --Larry Garfield