Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113756 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63949 invoked from network); 25 Mar 2021 05:41:03 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Mar 2021 05:41:03 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B9B3C1804D8 for ; Wed, 24 Mar 2021 22:36:59 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 ; Wed, 24 Mar 2021 22:36:59 -0700 (PDT) Received: by mail-lf1-f51.google.com with SMTP id o126so785315lfa.0 for ; Wed, 24 Mar 2021 22:36:59 -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=D86EtKvsiHuDSSSmXS3UxIYCOBu6ig6H+feHgsgd1fI=; b=fihGUwD1Cjld6qIGpxEdUBci/sWA13BCdUP/CBeh8CRkpB8OvZgGBuR3TICrOaGRn1 1MgD1Iaesh/E6Blz19198bamaT+3qPARdJXxPBx7y8Hbm/qUhBSZ1Gl1JeqGl7hNAJS9 Zs4vJoL8bzsRgQOfC1piIEcDWIbx1sDVwobQ78Iy72IVO/xlEACtGyDEOycYLgS7CNP7 NogEXdS8V8lHytdiRrvenFrRgsacVfZih/4mfTWHUyVZpJtYuhwS8HKQg4/dL5SwEIVv RzOsIakM6+xfF42qpjTVT9P4zYs5C8nOI3kmHVA8AKdVmvn7oyW3pgnIBp7ODW+8xS7i 1vGA== 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=D86EtKvsiHuDSSSmXS3UxIYCOBu6ig6H+feHgsgd1fI=; b=tXjXq3cRAhaDBjS/jCYErjo+1C+CNnLNehsIAEVdfg7XncsloaR5SxnU5aC6s9X64K bQpREC7ZRuhPiRymypbkTL38YF+FEOlfI+IvnZCfvJPZWIOcD0sZyP6l8b2O4bl/sOIS W4BaNTofaVKjvbQDVa/YursracF6S8rLQ4NBYRZP/U2y3ujK0NFfIBw+vIYwcQK6ZVGS Ygz/kXRyjMtmKGCLwo11YMhrI8OtPsBRKbZEUNo8HVMJdDaH+PdU/pBgy1XXgw7otuMM rtCmSla0dFThfYXKdUer2dWCAzQf4l0y+D60GJfNGUy1G/yHPMQA2rzDIrJieROd3FMp v0zg== X-Gm-Message-State: AOAM532ouLAo/ZOxU5qWnCu4HXWYcNcXWilZ5HsiTF2cGmV9GjJ2KKKY 44JrsDYP8za9x8IPQtzDNdeNuqf+wYpZNobqRN0= X-Google-Smtp-Source: ABdhPJxR+xhnBJDzz/kwUHzBtifVXbzsZIhGhCu9AbgFglTnj030xM2Kn7h4vgD3jhhyDw8RMGs3cdgr9hzDvNDkPdU= X-Received: by 2002:a19:6b13:: with SMTP id d19mr3811751lfa.291.1616650613796; Wed, 24 Mar 2021 22:36:53 -0700 (PDT) MIME-Version: 1.0 References: <88c9eb5f-f80c-4869-b7f8-1b58b9e2eaa3@www.fastmail.com> In-Reply-To: <88c9eb5f-f80c-4869-b7f8-1b58b9e2eaa3@www.fastmail.com> Date: Wed, 24 Mar 2021 22:36:42 -0700 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000008fb3f505be55cd2d" Subject: Re: [PHP-DEV] [RFC] Auto-capture multi-line closures and short functions take 2 From: sarkedev@gmail.com (Peter Stalman) --0000000000008fb3f505be55cd2d Content-Type: text/plain; charset="UTF-8" On Wed, Mar 24, 2021 at 9:20 AM Larry Garfield wrote: > 1) The updated short-functions RFC: > https://wiki.php.net/rfc/short-functions > > 2) A new RFC, code by Nuno, for auto-capturing multi-statement closures: > https://wiki.php.net/rfc/auto-capture-closure > > These are separate RFCs and at this time we plan to send them to separate > votes, but I list them together to demonstrate that they have been > developed in a mutually-compatible way. > Hi Larry (and Nuno) , Well done on the RFCs and making sure they are compatible and consistent. That said, I agree with the sentiment that multi-statement auto-capturing closures can add noise. It's not just a multi-line `fn()`, as their usage would be different. With the single statement and return of `fn()` it was intended to be used as a function argument where a callback is needed. There autocapture makes sense to me. But in the end, it's a matter of preference to use it or not. I just don't want PHP to drift closer to the callback hell that is JS. Looking at the two proposals, I boil it down to this combined example: ``` class Short { public function foo($a, $b, $c): int => match ($a) { 1, 3, 5 => (fn() { $val = $a * $b; return $val * $c; })(), 2, 4, 6 => (fn() { $val = $a + $b; return $val + $c; })(), }; } class Long { public function foo($a, $b, $c): int { return match ($a) { 1, 3, 5 => self::bar($a, $b, $c), 2, 4, 6 => self::baz($a, $b, $c), }; } private static function bar($a, $b, $c): int { $val = $a * $b; return $val * $c; } private static function baz($a, $b, $c): int { $val = $a + $b; return $val + $c; } } ``` The Short class is "fine", but I would still prefer the Long class. Thanks, Peter --0000000000008fb3f505be55cd2d--