Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117927 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10112 invoked from network); 13 Jun 2022 08:41:16 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 Jun 2022 08:41:16 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0DF4D18053F for ; Mon, 13 Jun 2022 03:28:30 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 13 Jun 2022 03:28:29 -0700 (PDT) Received: by mail-ot1-f42.google.com with SMTP id a8-20020a05683012c800b0060c027c8afdso4056612otq.10 for ; Mon, 13 Jun 2022 03:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=QdgCq80FTV4aLf3N9Gl9+P5CFPQwBwGUnMQJRLbs5vs=; b=oaJprzcYHUb5uB/ificDX4lwOW/e7/HmR5kQqmZLGBYL2dBPyF9sn6jO8GCbXjC/ai DIGy7QE3G2I7hQQUBKx+cCJSdGzeLwSg9ZnDfLzZ7ieacS4F47/KxsirTaPL5iMxiijM 7eU/8/0V/k3dPVhnEu9Dmtg9IZTBkJBLtpm84QpAmdZAN9xOBOkXmjfjEhq65vX6zp1X dsmgwrIhe+Tl9S3leV4pYwuxYZk+AahDwDENhkyYejWgPnH1Ph9DQ3WORoIifJXp9u2x NRfYKtHClCJgD1AzyninaFlLP57v1FTLwiKBndSn7UXigb33hjMWEl4c65x4M6Rt7ykv halQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=QdgCq80FTV4aLf3N9Gl9+P5CFPQwBwGUnMQJRLbs5vs=; b=B22XABA8Q/4pXCtYxyiNqaitH1gDM3q6cK047SZhEJTug8BcxOPwlwq5rl5VPGnTVs +xnG63ByHLu7CRcRi0Grad8ss4b7O8AlTzxshNPyV3cZfnZA3amz0Vu0zV8umwZe5OdK rOQatbzZuZNYp1N98bz9OkYhHA2gAdvxZqP6njAlQpwsBnyVP/2k598JLNYXK+oMM9K0 jTeuT5E8FUbUSWmdgZAwaaYsmctmUbvqMnYD91//4tnlxdhSreIzZjMXsAtiKjRrC57F 8TzkYMnNxJBCv5REnXa2STRjvMoX3QZdAuUz/anKlQZYqGg1IHXY7Z1mhgJSmrRJrMbF bhAA== X-Gm-Message-State: AOAM5322QKcODkm1o36BNTMfw+4wJBakBjjLOcnB99ejwIVGysM1+vF6 PTMeHv3SoTRtG/HGa84rPe/OiYcLcNi1PZ5/gPw= X-Google-Smtp-Source: ABdhPJzCpqkp03LVSKVfE9pkhw//tz9OlLDTkyLqBLeze5FAfoo7RSNKsfvtV+nKA7oke9FcIowiys234tyJ+GqWrUw= X-Received: by 2002:a05:6830:2a0b:b0:60c:742e:a09d with SMTP id y11-20020a0568302a0b00b0060c742ea09dmr781411otu.349.1655116108957; Mon, 13 Jun 2022 03:28:28 -0700 (PDT) MIME-Version: 1.0 References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <2279cbd2-fcfe-460f-97f9-0029b7b043bb@www.fastmail.com> <036bb10b-3e21-8516-db56-75a8c0fa964e@demon-angel.eu> <827956617.0ifERbkFSE@arnaud-t490> In-Reply-To: <827956617.0ifERbkFSE@arnaud-t490> Date: Mon, 13 Jun 2022 12:28:17 +0200 Message-ID: To: Arnaud Le Blanc Cc: internals , mark@demon-angel.eu Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: landers.robert@gmail.com (Robert Landers) On Mon, Jun 13, 2022 at 11:36 AM Arnaud Le Blanc wrote: > > On dimanche 12 juin 2022 19:54:06 CEST Mark Baker wrote: > > Did many of those closures use "pass by reference" in the use clause, > > because that's one real differentiator between traditional closures and > > short lambdas. There's also the fact that use values are bound at the > > point where the closure is defined, not where it's called (if they even > > exist at all at that point), although that's probably more difficult to > > determine. > > Please note that auto-capture binds variables at function declaration. This is > the case in Arrow Functions, and is inherited by this RFC. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > From a maintainer and code review aspect, I prefer the longer syntax because it is 100% clear on which variables are being closed over and utilized in the anonymous function. fn($x) => $x + $y is pretty clear that $y is being pulled in from an outer scope but if you start getting into longer ones, it can get non-obvious pretty quickly... $func = fn($x) { $y[] = $x; // do some stuff return $y; } If $y is pulled from the outside scope, it may or may not be intentional but hopefully, it is an array. If anyone uses the name $y outside the lambda, this code may subtly break. That being said, I'd love this RFC broken into two RFCs, one for generic auto-capturing and one for multi-line fn functions (just to reduce some typing when refactoring). There are times when auto-capturing can be useful for all lambdas, especially when writing some custom middleware.