Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112000 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42803 invoked from network); 5 Oct 2020 10:44:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Oct 2020 10:44:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 891411804D9 for ; Mon, 5 Oct 2020 02:57:14 -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.3 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,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 mout.gmx.net (mout.gmx.net [212.227.17.22]) (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 02:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1601891828; bh=NxF9GseMV6/+pHxLvdsZ5X+af4oFGjXVm9ACrBMb+J4=; h=X-UI-Sender-Class:Subject:To:References:From:Date:In-Reply-To; b=jtK4hmqDhv0beBPvoHlYhOKOxQeE2gQAfIlDTuauQrTQt0v3ULqwWRPAwMu8cP96V b3NmA5pF6hRdLZjmBQAKVt3/neongg8O3Xz7rU1+vTGLcZHsKYLsRXM/ptGIfTssss caUnxfOYioYezQcjNkt2sPp8JCRRMRYZ+Kzmf8HA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.178.120] ([24.134.51.41]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MUGiJ-1jyb953Jbv-00RKZF for ; Mon, 05 Oct 2020 11:57:08 +0200 To: internals@lists.php.net References: <446c9894-191f-e53b-4534-31c4e7b91d7b@gmail.com> Message-ID: <881e2335-5f81-0d79-6a17-06bc20f14223@gmx.net> Date: Mon, 5 Oct 2020 11:57:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <446c9894-191f-e53b-4534-31c4e7b91d7b@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Content-Language: en-US X-Provags-ID: V03:K1:CoAwUU7enq62KfsI7yFntsIlNLtfYPRKifm7OnEIm8ZR0US0HLZ 4CPFtthareol/H1mAYVPoboRnxDw4Wn+rCXeTTQpnN2Y3YgKedaCsbDduWfJfRn5xQvpEXF SXZShemBLnSKJ7tmLyrqz+5VpXXXKLjUFf8ZLfjbICLCmBSANrJgF8b2eheEgtwxn1IqfGY fRK3GWB1Jqg96Wl4ycbVg== X-UI-Out-Filterresults: notjunk:1;V03:K0:Kp/4NeiJcsA=:xp1C5LsVa63poo/dlBpcGZ AJcRhWYvL8sqLyZVmG12DM8PTMoFHGlYjTRJlUFsYVoos+ZcyDaHSSF9uFLT12X5XVVYIFh9f opEyY9oUHdLQqfsyJVe9Fw9hKQgm5Zg+ZwCBRWa4Xy83hoa+PPqG6JwCjGTDj1ZzXwNkAR861 GTRiYYxucaxxbAyATlG9O1+uQ5KLwHNzubjhfopPwBJ/vYryFKbQJnXPuDuLEpn6cVHqyEJ+9 wYn58Og0flmqgZ1LeD/r3O6e+Zf8EL0iP7add3MKSq0s6ZOdYWekj3axM/Kx8HQKGoELnlbD7 nuVXuWrINWxLUwcYkTMPIPWCIHoFTp0zCr12h11jbEG6gancMoK4F2pI2cDBfAJ4/0z+OzaBb eOdyUmeiHsR6fl6CGRjxlU3shcBWXNaMGI/Jt0KjCEvagcXA/Rk09SkXmvwsUV31TBsNOJOL4 z6TW+WA3+CnrhsMPLy9cKr2bEyM8G4+NVZtV5QppYQaIp04OjvVivtrdzQb+0kjalXTX8cWda yK3zncBylHRoezJlIu1C3d3hGU7JGhuGENkkmLp2pV7OLbpDA3+e41h/Dv0/QP1ZrCIfNH0C3 +nATwXsE48rRsqsV8o1ymckgo4DEoDiumE8vBj4zAKZz60As37pXmmVKLIVL/NZoWT5OgS59T Vfq2vmGTaVqrsro8VvIxCq6+xj/z9PKtF9LuNZ88Sgccx6ASKm/nCYPy8jMm4W8DIJRGOOCGF HOtMu6jAw5G23hEO16x7SP9hbKZQXOGgZWSYzkxPi48bGAsoGKRRF/DwTDC0H26Z74U09poYJ 8ZGjSgjotiBDn8CR2UrABgLeFzoH8SZvzbbk5gt8UEDdXj8PbwrBJDFx06F5ijU14HuXAohOP VkVQ7arTgx5IwUFPoMLJAMA0x2x6CNS4tKMKx2JuSBoS+VY24YjsIxyzmyABSTFSvQLrOjiUw up6WMpQf/9c3txqt77JAp2xD8Yckv6jWf2miyB+XBN0jhdIbMMm/h+DXajRF6LIFZ3VwLC1vr 3G8OdCEkErGeTqczybeV/rw0mdj+2HUeG++cgO1IoqKRXjqw/bbCRr4qapgcL8RD+s6uTDdAz gmiNegWILjPssL6OujjdV0a7nDEhUc4pxQOpunpmMFNLGygOGewXMzchA5xZLTseQlrSS57y3 gfuGBnGfog8yYbgld7k50Uplum+oWUGbZafyJYesMArnHMxpyZufIxcA8pj9sO2+c9UunzSze aN8nbHbLV5qhhtrce9CS8ojIVAMj3fciYKtdWfA== Subject: Re: [PHP-DEV] RFC: Support for multi-line arrow functions From: a.leathley@gmx.net (Andreas Leathley) 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 (*) { > =C2=A0=C2=A0=C2=A0=C2=A0 $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 { =C2=A0=C2=A0=C2=A0 $this->transaction->run(function () use ($numberId, $a= ddressId, $isMainNumber): void { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // Do all SQL queries for the update =C2=A0=C2=A0=C2=A0 }); } ``` 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 { =C2=A0=C2=A0=C2=A0 $this->transaction->run(function () use (*): void { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 // Do all SQL queries for the update =C2=A0=C2=A0=C2=A0 }); } ``` This would also increase code readability.