Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117951 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15661 invoked from network); 15 Jun 2022 10:18:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Jun 2022 10:18:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 64C6D180545 for ; Wed, 15 Jun 2022 05:05:53 -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_H2,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-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (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 ; Wed, 15 Jun 2022 05:05:52 -0700 (PDT) Received: by mail-yb1-f178.google.com with SMTP id t32so20066379ybt.12 for ; Wed, 15 Jun 2022 05:05:52 -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=cMoNAOm8582WYwQFA8+VZaCaNNl+xkW7r8XV4NA97lM=; b=ml977KEeRGlylgTPZxoa7EGpP1u2nvS8k8GeFjT/UOrToDGiE66lIlf6gmrHfhJzeJ RIi0IVbcklZlShHpGJE4TUwxKW1xPHxwfFpLh1wBR4x8PJdmwG6rLUbp0ecSdZmHLuBx Q/sDegqurZBjLr6MQT+tPWG4XYV2/PxKDVzCCv6P9FJOyvsOtEKJQ1z2Jv7kEmuOoNBr nnkbPriZTi+tKrvov+geLvAC0loFLr9IcMqDa/S949yUHrVUsNavgx5EYHBkcsjd4IYK x0gT2PwuLuChRmFf2A5A9Zgb4pKaJFRi1AVa7qYEQnZHImG9s/EprHJsJARmU9owSi0Z 2meg== 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=cMoNAOm8582WYwQFA8+VZaCaNNl+xkW7r8XV4NA97lM=; b=TWFU2O0da/cpsTdw5kcWg/61UkozfgxIk2gioQirrs/9JF3Sa5hRWNz7DoAsLVtQRq E16pU8U9mWi0CxcNBgrOOLZIlcjssvGbzNfuo4rXhd+xPoOA22DQ7nHeYQhunDkV/+xl ZMuPnIgHQPHHHsJGAsASMrKh4JwdINIDvE2Vx27dr9I2YJTvA5vCf7j6r2kcedGN5Pj5 Dlq9sR6CTdzoH++TCfvvKXshjjFBZOu3O+IQ6vQ5I5E60kILHkhBwArQaO2mdr0y0qhj ax++XsqZh9NZ+axnFLcOBU/9at6ZGOYfSLb2uPazaLk7HsktY2PoOAMopW9Z5el7dIqf JH1A== X-Gm-Message-State: AJIora8pkvkx+nfH6Cg3qdPQGF2yKxbE5w+eaeYcd9dOtXR+rw45ties iXGvevNzhRZ4H/Eb6EjsLYtt4mgVl112/CaMFA== X-Google-Smtp-Source: AGRyM1vvTz6B9Er4MZ1w6sg5epp+SFGNpaA3hmOs03wLDJn8UsfG2ijUSk2AKY85MtJhvCx41sFPsQ38MFPLClKsWo8= X-Received: by 2002:a25:6787:0:b0:660:7392:9a36 with SMTP id b129-20020a256787000000b0066073929a36mr10271663ybc.402.1655294752288; Wed, 15 Jun 2022 05:05:52 -0700 (PDT) MIME-Version: 1.0 References: <2b35605f-8da8-46b1-aec3-00bd1bfe47fd@www.fastmail.com> <2347345.PIDvDuAF1L@arnaud-t490> <11078866.5MRjnR8RnV@arnaud-t490> In-Reply-To: <11078866.5MRjnR8RnV@arnaud-t490> Date: Wed, 15 Jun 2022 14:05:41 +0200 Message-ID: To: Arnaud Le Blanc Cc: internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Short Closures 2, aka auto-capture take 3 From: guilliam.xavier@gmail.com (Guilliam Xavier) > > > Because variables are captured by-value, Short Closures can not have > > > unintended side effects. > > > > Those statements are true for scalar values. They are not true for objects: > > This is shown in the "No unintended side-effects" section of the RFC. I'm confused by the last example: $fn2 = function () use (&$a) { /* code with $a AND $b */ } Isn't that missing a ", $b" in the `use`? And like others, I also find that allowing mixing explicit *by-value* capture with auto-capture is not really needed and even confusing; if you "expect that explicitly capturing by value will be rare in practice" you might as well forbid it? Maybe you don't even need to add explicit [by-reference] capture to short closures at all, but rather extend *long* closures so that we can write things like: $val1 = rand(); $val2 = rand(); $ref = null; $fn1 = function () use (...) { /* do something with $val1 and $val2 */ }; $fn2 = function () use (&$ref, ...) { $ref = $val1 + $val2; }; (and even if not, at least mention in the RFC that it has been considered)? By the way, what about *arrow* functions? e.g. $fn = fn () use (&$ref) => $ref = $val1 + $val2; // assigns and returns Would that be allowed? Is it really *desirable*? Regards, -- Guilliam Xavier