Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112003 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47717 invoked from network); 5 Oct 2020 11:03:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Oct 2020 11:03:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8BB791804D9 for ; Mon, 5 Oct 2020 03:16:04 -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-il1-f179.google.com (mail-il1-f179.google.com [209.85.166.179]) (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 ; Mon, 5 Oct 2020 03:16:04 -0700 (PDT) Received: by mail-il1-f179.google.com with SMTP id q5so7269571ilj.1 for ; Mon, 05 Oct 2020 03:16:04 -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=xMCzFeJrSzF1Jpend632tKLwMFs4QBJOq7nGNAKUwYE=; b=N6Txa7UQg6FkFZryJXpiDCiwM2b0sSC9p3QFH8Otpu1ES6B0C+lZlscGfZxwGD40wR 7ami5JcdNEiMzLm2cbexbE3aNKEbuS2bbq7NGmD856gPv3VVoEEYqpE8CLchIdj1z9OU yxVovC3WAM2LEF2f59dMCymzR7f4ObizEIrqu5EVS++1Cgexe43yFKVs8DKqIJz22XEE JAReGxsOXeLyEBwB/CU5Rr1oEJkppuPJo0hExr+w+9LIKWqjIKwXEq+4P7CpukoLLL+z 0cSJCilCiw3SwKxuhnEOOonyB6vB9k3RvCJVkFDGqS9X/00d6EPzkWPVLHziJDDoDnxi CKWg== 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=xMCzFeJrSzF1Jpend632tKLwMFs4QBJOq7nGNAKUwYE=; b=FMk4Hg/yovmXznn/i4TzoZjIHE0MtUNR8+2ZS/ZObOnZj1mSfVtnc9HBH7lND/DSDD wMAxlWE/7yfflfYTMYeJBWJvRVXfc/TpM3WaEHV/u81Gu6Pwcm+2gGmibp10zGbRe9hZ eB9+pc41TgqUeQfhyzAHTFnVm+fNj+gPOPMsYEYEuCiwtfnELG9RCHnw/SBc7WqqL5X1 /2wbkBNzhEITuOcSQ3ZtsNxJ+6twY0hGqN1CM9uH+3nPdYJlOKEVM3nkf9DbhNyJT7pb 5sUNrtLr2jLX3NWPGSOHO37Dt1nVfM2agI5n2NRMW4jOc/MXy5yNNSl9CBgwfMdvBZjo zbHQ== X-Gm-Message-State: AOAM5335Tyiugbhbm4s63HyxGrmlii74AizsHf6CdH+WtV8AiTYYh2pW QrZOW0zvwwGNHSo577J2onAPyMq3DrTNDqUEP0E= X-Google-Smtp-Source: ABdhPJyXqrSJ3f9a+S+8hgU6zwrGejM8jYxVHycFy1WwC726mil8ZtsDlE/wYV5BfTvTGMLcsWBSDTURtQagAK6l5VE= X-Received: by 2002:a92:9907:: with SMTP id p7mr11207145ili.200.1601892962570; Mon, 05 Oct 2020 03:16:02 -0700 (PDT) MIME-Version: 1.0 References: <446c9894-191f-e53b-4534-31c4e7b91d7b@gmail.com> <881e2335-5f81-0d79-6a17-06bc20f14223@gmx.net> In-Reply-To: <881e2335-5f81-0d79-6a17-06bc20f14223@gmx.net> Date: Mon, 5 Oct 2020 12:15:27 +0200 Message-ID: To: Andreas Leathley Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000000963005b0e9c57c" Subject: Re: [PHP-DEV] RFC: Support for multi-line arrow functions From: deleugyn@gmail.com (Deleu) --00000000000000963005b0e9c57c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable To me that seems like a great argument in favour of the proposal. If you'll want all variables to be imported (which in this case makes completely sense), then `fn() {}` or `fn() =3D> {}` is much less verbose and inline wi= th the mentality to reach for short closures. We reach for short closures to avoid `use()` and convey that the outer process is intertwined with the inner process. `fn()` allows to strengthen the concept that there's no real separation between running SQL stuff in a `callable` that wraps a database transaction. On Mon, Oct 5, 2020 at 11:57 AM Andreas Leathley wrote= : > On 04.10.20 22:08, Rowan Tommins wrote: > > If we added an opt-in syntax for "capture everything", we might > > instead write this: > > > > $f =3D function() use (*) { > > $x =3D $y =3D $z =3D null; > > } > > > > Without re-initialising all local variables, we would no longer be > > able to know if they were actually local without looking at the > > surrounding scope for a value that might be captured. I am unconvinced > > by this trade-off of opt-out instead of opt-in. > > > > One use case I've seen proposed is closures which capture a large > > number of variables; I would be interested to see an example where > > this is the case and is not a "code smell" in the same way as > > requiring a large number of parameters. > > Something like "use (*)" seems like a great enhancement to me. I often > use a wrapper function for SQL transactions, something like: > > ```php > public function update(int $numberId, int $addressId, bool $isMainNumber > =3D false): void > { > $this->transaction->run(function () use ($numberId, $addressId, > $isMainNumber): void { > // Do all SQL queries for the update > }); > } > > ``` > > In these cases there is a lot of redundancy because of having to import > the variables, and if a variable is added, it has to be added in two > places in a slightly different way. The following would be much nicer: > > ```php > public function update(int $numberId, int $addressId, bool $isMainNumber > =3D false): void > { > $this->transaction->run(function () use (*): void { > // Do all SQL queries for the update > }); > } > > ``` > > This would also increase code readability. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --=20 Marco Aur=C3=A9lio Deleu --00000000000000963005b0e9c57c--