Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110293 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73302 invoked from network); 28 May 2020 17:32:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 May 2020 17:32:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 35F9A18054A for ; Thu, 28 May 2020 09:13: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=0.6 required=5.0 tests=BAYES_50,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, 28 May 2020 09:13:07 -0700 (PDT) Received: by mail-yb1-f176.google.com with SMTP id l67so310328ybl.4 for ; Thu, 28 May 2020 09:13: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; bh=oRyZOlZu8CMJ6AsGLr+5DXyHw787HdisZOyb1S4okdE=; b=bJq4muqWxSmPB8lqpRrUjwMhLFDcO63FyVH/H4L7NOgYbGA11HxyXNetDfJg8JJV7i MVNySA33hNgg+Z1CqTtv/Zl8Cug/v50PSy1E5FerB4yo9isfwd25ch+pCpwh1Oivuof3 fpzDTpuMbI2wTY5RSMz+FCg2sBvJhJAx5lDeZIiBMgVXHWm8NrIfaEBnZSkwr0f83g3u 4HR2yY54RbAKA6KuSNH3KkHed3PB7+lN3/DgF+f0izOfqpTTIW/ssBH2g5crrZAgSOIW 6FBnh9E5/s+SKESkr4/BSsXYh1nd9562IcrnVLWeseb17/KjIBhttLUabwOGZqwLm9/o QPWw== 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=oRyZOlZu8CMJ6AsGLr+5DXyHw787HdisZOyb1S4okdE=; b=aI8ZaWPKMEhUu5Tso+5MSJMQ5wj8xkGb3bJrTfrgsbOdpf0H+ZQ06QZsReheiCOVy3 OrQHlDw7XI4ZqenZRk4k767leNlM0O/BgjmVlM74lThPjfpbFUB7AnWezRx6jUxpiDog EZAPQ6Z68SMNTABc7mETG1QXFhoalecVytz2T0R0QNc/BchXDXuwQCQD6MLIv3s6BqcE HInE/OtEQhFFmTocaDiI2rb5oxlXFRRJe28vNkScdWiIezdAgRICQ+GmX2Rt42knfe+B aJNLhk94ZhkxDxKk4/407lg48R3iOOIf41mxn1/Uw+r9r16k0w3vCuvQXT1bBAMyVKgt V9OA== X-Gm-Message-State: AOAM531SYLPxswT0oAypvzQ9Q+/HIu6EVuXOW4byTNedwNecFrfbAFtt sYo9vzcM9WPECmRQmyfbzCcBUdgmbbAYqX0c2/Asz8oY X-Google-Smtp-Source: ABdhPJz7hf2lk2VXlWwk+5rgzBnlLAPlgG6kv3yV4wadEL+oK/Dnk42gkh7GPdfF0sIqxhdFYVqwz8xjG8QvwABoK2s= X-Received: by 2002:a25:9010:: with SMTP id s16mr5677530ybl.2.1590682384844; Thu, 28 May 2020 09:13:04 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 28 May 2020 18:12:53 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Match expression v2 From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Davey > I mean, ultimately, it's equivalent to: > > echo (function($match) { > if ($match === Lexer::T_SELECT) { > return $this->SelectStatement() > } > if ($match === Lexer::T_UPDATE) { > return $this->UpdateStatement() > } > if ($match === Lexer::T_DELETE) { > return $this->SelectStatement() > } > return $this->syntaxError('SELECT, UPDATE or DELETE'); > })($this->lexer->lookahead['type']); > > The main selling point for match is that it's more concise, I'm not convinced that the return if variant is much less concise. If you want to match more than one thing, use the OR (double pipe) operator in the if condition. There is no ultimate right or wrong here. For myself, there's a lot of cognitive overhead reading the code above. For others that might not be the case. There are also some other benefits of using match, like the jumptable optimization and a smaller risk of making mistakes. > If we are doing this however, I'd prefer to implement Go's switch block, named match because we already have a switch. It's strict, but flexible. Since most people expressed a desire for the match expression with no blocks I wanted to introduce the expression first. After 6 months of using match opinions on blocks might change, or they might not. If we do introduce blocks match should be able to do pretty much everything Go's switch can. Ilija