Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111371 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 75210 invoked from network); 8 Aug 2020 01:37:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Aug 2020 01:37:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5AE201804C8 for ; Fri, 7 Aug 2020 17:36:08 -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.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-il1-f172.google.com (mail-il1-f172.google.com [209.85.166.172]) (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 ; Fri, 7 Aug 2020 17:36:07 -0700 (PDT) Received: by mail-il1-f172.google.com with SMTP id 77so3212006ilc.5 for ; Fri, 07 Aug 2020 17:36:07 -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 :cc; bh=r+ypD8Frz1UBz7j4YwOawCVgNWne/1Dh/uMr6vhqfIw=; b=CGhF1qMV5P+ikyQ00ESfBg1p3mkOuYOTufqSVgjP30REEGvB6j1s/p6db7FCqXWgzc dsFhQnFmte3xuVoPe5a+HGwciHpv+LddtT6YCg0Lpjfsnsd3q6OsCnqJ5h8yYwgsEPSm xe0LCkIJD80ZLtxaUFnrOcnh4EtvSb5XqhpyzXnKpA9zY7uNwS6VVFS1N+IT79YOdRq5 Xn83DAC96OfCiGBU37G0ZDQNNPllsCZgqVxw4b2pyUN4Ef2IbhWCPZpWfUTicSH8ROHa zeUvcansTk348eWPfFMeJOFI2B8lTqoj7vUTkmeXbZCEjjKFPfrKl4obFWaqg81i/x39 NyKw== 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=r+ypD8Frz1UBz7j4YwOawCVgNWne/1Dh/uMr6vhqfIw=; b=IIotvy+W03GSRI757mqkAFZHAsEJp97JPZoKpj/FFV03qAzhvQHptbX/KPobIXUphV WOYGNr0ihzzOYvuP99ctXQDvASbHTM6k7C7RBd14326gKcnTKjpUtU2udXciFEhFbhWr CKasOiWNGS24HB7iWQ+BbMRs4agH68R+CmW5cHKGf1Uk1bbLLBP59C0ydyPpMMnMueTp PtkllFRQSm92PKFHU1oQsiPOhRZn1BsNuWzRcH52JKH2XhsvYfLov6nmrYPtsGSSJbKO EM+gWKND/P+tQZlhlckXkZFZljdZ9sFF/7FwnsShRKQV6qnEn3jYhc/omfoRqsOb2CW5 DpmA== X-Gm-Message-State: AOAM531+1SJnjfONP1AJyjgOZ2o6FJXhmJ6Dl1bAAvuzd0dje2PZwd2B +KlgtZ6z2yuYXHHOGcYpjiIy0lFElLyzoUHp3e4= X-Google-Smtp-Source: ABdhPJy5LWsDn3SUmxGv8y3uVGL6D3MZ7NQwRpeLVQSwudgIZYsQgIiemi5VxINiucnbuNXopqbZRwqA7E/vOT+kS5c= X-Received: by 2002:a92:c5cf:: with SMTP id s15mr6209797ilt.99.1596846966429; Fri, 07 Aug 2020 17:36:06 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 8 Aug 2020 02:35:50 +0200 Message-ID: To: tyson andre Cc: PHP Developers Mailing List Content-Type: multipart/alternative; boundary="00000000000031e07b05ac52e8b0" Subject: Re: [PHP-DEV] Putting the match expression in constant expressions in PHP 8.0 or 8.1 From: carusogabriel34@gmail.com (Gabriel Caruso) --00000000000031e07b05ac52e8b0 Content-Type: text/plain; charset="UTF-8" On Sat, 8 Aug 2020 at 02:22, tyson andre wrote: > Hi internals, > > The match expression can be thought of as a much more concise/readable > equivalent to chained ternary operators. > I'm proposing allowing matches in constant expressions when all parts of > the match are constant expressions. > > For example, these two class constants would have equivalent behaviors if > match expressions were allowed in constant expressions. > > ``` > class MyClass { > const CONFIG_SETTING = (APP_ENVIRONMENT == 'dev' || APP_ENVIRONMENT == > 'stage') ? 'development-config' : > (APP_ENVIRONMENT == 'prod' ? 'production-config' : null); > > const CONFIG_SETTING = match(APP_ENVIRONMENT) { > 'dev', 'stage' => 'development-config', > 'prod' => 'production-config', > default => null, > }; > } > ``` > > https://github.com/php/php-src/pull/5951 implements the main part of the > change. > > This is mostly for the sake of consistency, since match can be thought of > as yet another control flow primitive that is more readable under some > circumstances. > > So I had some questions: > 1. Should this target 8.0 or 8.1? I'm leaning towards 8.1 since the beta > is already out. > 8.1, as PHP 8.0 is already FF and I'd consider your proposal a feature, we'd need an RFC and everything else :) > 2. Are there objections to doing this? > 3. Should/shouldn't php enforce that the default arm exists for match *in > constant expressions* > (constant expressions can already throw errors when evaluated for > various reasons, but UnhandledMatchError is new) > > Thanks, > - Tyson > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --00000000000031e07b05ac52e8b0--