Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105960 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47457 invoked from network); 17 Jun 2019 18:23:31 -0000 Received: from unknown (HELO mail-io1-f43.google.com) (209.85.166.43) by pb1.pair.com with SMTP; 17 Jun 2019 18:23:31 -0000 Received: by mail-io1-f43.google.com with SMTP id e5so22213704iok.4 for ; Mon, 17 Jun 2019 08:37:42 -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; bh=Ro+r0wMksOPWtsmjePMHJ56B49zUCAF5JBK5uKTljE0=; b=SXuIBTv3sfRLp37xf2YlSjzvDc1er/8t3xA0+cAH/GXr3sOeEFJU12tAZ3Kc1Cr7GH ZFbTy37lYfL4/n6jucuzlus0Vjq6g0XMLrMdpn7JZbRnVoGn4eX8oeSXxcpFZdX5/TZr TABHm8UAqcLPznUZ8rPNuyFc6qcc9J497a9QxaMnyPPE4LRr0MdhZO7hX4mCK2QlpkN0 HPDKJFvYlRUpcshPT/oAP48LRwdjs5j51V4b7+E42wgTra/aRzOTEECWUjQGqA/RL80c 4p3au7GN1fS864nOEUYK5WbtenJ8xoW2Ds29VGPXoXgT6tBCq1nY19nSryMVD0fSbs+9 yiOQ== 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; bh=Ro+r0wMksOPWtsmjePMHJ56B49zUCAF5JBK5uKTljE0=; b=mOGjHPvPun6p2XWHyQiz/IS6ur2jnwJeacFRu/NOzObgI7zX+ATZi17ftqFhsz5EtQ Tf2wHX8l+XH8lQkOXp/iXYXE8Gq5MxxbgV0I6ibv3Tc52Wc8XdikN0UUruPJOKdacPSl 2dI0wlZ479w58A8aSWI/Nrhqzb7RTqrEmh3d23N5y31aBPjOkk65v6us366ayQITZd3m 84qBzsgfN9BxtgKBg0RJTxZNNjqqHR1iFjp6TR1VvuC300VqYOun/4NtUZhK8foSM3N9 bsaSGAqF+tx7OlxhQ2B38t+n4ZPsGyvRyTwKYnsVMDULgebRv9rAHzmIoAGOKkYyX/5a Li8g== X-Gm-Message-State: APjAAAV0ByTKPOvsvlfN9OXLkJeiB73I6etGnckxTkOuYXUX8TNVQ6/I Ys3/c+CPRyylj9t0nD/xf5kgB00PjBduvgcY7/vIGwnL X-Google-Smtp-Source: APXvYqwgeU26YoC6jjQ8eLKxSvRrhm4UYXGWnD0QqwUjLLvCPgijMQYFsAqswlagQfIDUW79r6nr6XQwbGRmYJBk+6g= X-Received: by 2002:a02:ab99:: with SMTP id t25mr72831033jan.113.1560785861040; Mon, 17 Jun 2019 08:37:41 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 17 Jun 2019 16:37:30 +0100 Message-ID: To: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000d1612c058b86c6e5" Subject: Re: [PHP-DEV][RFC] Alternative "use" syntax for Closures From: rowan.collins@gmail.com (Rowan Collins) --000000000000d1612c058b86c6e5 Content-Type: text/plain; charset="UTF-8" On Sat, 15 Jun 2019 at 23:22, Kalle Sommer Nielsen wrote: > The proposed syntax was also that of the proposed syntax when closures > arrived in 5.3 (and back then it was using the then keyword > 'lexical'), anyway. I believe the current syntax was chosen due to > scopes, as values are bound specifically when the closure is created > and not when the closure is executed. > Hi Kalle, Thanks for the background info, I've often wondered why the syntax isn't more similar to "global" and "static" declarations. It hadn't occurred to me before that the function signature can be processed without inspecting the function body. While I think the proposed syntax has its upsides, I agree with others that adding it as an alternative at this stage doesn't add very much. People who don't like explicit imports still won't like it, and people who are used to the existing syntax will write style guides prohibiting the new. When I suggested on SO chat that a long list of imports was a similarly bad sign as a long list of parameters, I was scoffed at, so I would be interested to see examples where large numbers of imports are justified. Assuming there are such use cases, it seems like automatic capture will be a better solution. I'm not personally keen on extending the arrow syntax with a full body - "fn()=>{}" is barely shorter than "function(){}", and I think "arrow functions are for short expressions" is a useful distinction and constraint. If we really need automatic capture, I'd prefer for it to be opted into in the normal syntax, e.g. "function() use(*) { ... }". We could even have "use(&*)" for "automatic capture by reference", if we wanted to go that far. Regards, -- Rowan Collins [IMSoP] --000000000000d1612c058b86c6e5--