Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112226 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78516 invoked from network); 11 Nov 2020 19:15:05 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Nov 2020 19:15:05 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 351A51804F2 for ; Wed, 11 Nov 2020 10:37:34 -0800 (PST) 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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 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 (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 11 Nov 2020 10:37:33 -0800 (PST) Received: by mail-ot1-f42.google.com with SMTP id n15so3066415otl.8 for ; Wed, 11 Nov 2020 10:37:33 -0800 (PST) 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=l3H+VAG5iKS0/JaaFtQfS/dY4PtOeV9rtB8XykGgJhw=; b=cbOmyz1VE0cgD1QnaITQmexraz0GJdkBZSRC0OMgxckyGmJGEx8e4txOiYE6rot9uL L/Lw5CQKbI3TZMVUJY+H/PoEofLD8RF/tSrMRuvJU5KVSwcbcvDvUPUlDBrVE/w6fCD4 UMm6sKHU2u4nZCON9eo5FPaudRUYSwsJp0rp9FsdOKiOxtgZwBwghfBdc+NnIOvWwA0J mis0JulqItSyBPFJuFfx6He6AeHKuggp5+FAmfXM/p6QUyv/QyKdrg+wOmP4KTBCvBb+ 3SoF6RnaXUMY/hMMAzhdcPSsqEgGGGbcPlrFyHQ++FtDaq8LORWhKrE+U580BAoHyp/q QbgA== 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=l3H+VAG5iKS0/JaaFtQfS/dY4PtOeV9rtB8XykGgJhw=; b=EDIx5p1GWJ8aQPNLTfKYY3zaZZJKFT4Cw2ljWiJPSCaB+xN5ttcJ2cYbyomuOlsADq qya5/mV0ItGgJ0EleFButzq08eu9loabwLZ+3RSZTA9ksICxsoNPA3YyjPnJVR2SIi2j ozS+0MVDAjkGLQE/qSqRIXITfyD1VDTI6++DQGe66XbFKID2Ye/17PoeycYTUmTgfWCc 6gb90cX+AbwYx5PrSw+Jkh1JNdpOZz0cvk7VSozuVwfFGxm1NjG1J2q7hcHAEQp/x6HU zZIbwJtgqB9Buj3qG8s5NnISPh4CbSnEZb7AMB4tRdvSt0MUhAAhfZDO2hrlRkoZ5rDt phoQ== X-Gm-Message-State: AOAM531h5aQ6OxRsaO8jLSGyspkqpzNsL5r5NRhmDj22tffQg6OxEoSd ixxZ+CPwBWTZm72GM2fg8n9WRnAMJFwMGteObjM= X-Google-Smtp-Source: ABdhPJy1c08j9lM7z4jhhgR6eJVjwhZ9I7YDkwORN9SoabHUY2lOwoqctGrErtk8R+G6rj1Z72dHpo93oOWR1KWHENY= X-Received: by 2002:a05:6830:1411:: with SMTP id v17mr19577130otp.209.1605119850605; Wed, 11 Nov 2020 10:37:30 -0800 (PST) MIME-Version: 1.0 References: <55e200cf-ed16-e935-4e09-728ce3362cba@gmx.de> In-Reply-To: <55e200cf-ed16-e935-4e09-728ce3362cba@gmx.de> Date: Wed, 11 Nov 2020 15:37:17 -0300 Message-ID: To: "Christoph M. Becker" Cc: Dan Ackroyd , Hans Henrik Bergan , PHP internals Content-Type: multipart/alternative; boundary="0000000000008470c105b3d91687" Subject: Re: [PHP-DEV] [RFC] Draft - Closure self reference From: david.proweb@gmail.com (David Rodrigues) --0000000000008470c105b3d91687 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I think that introducing a new variable, that even uncommon, could cause BC= . My suggestion is to reuse the keyword `as` to set a variable that will represent its own closure. It is more flexible once that we could choose any name and reuse in nested closures. It is pretty similar to how SQL works too. function fn1() as $lambda1 { return function() as $lambda2 use ($lambda1) { return [ gettype($lambda1), gettype($lambda2) ]; }; } Atenciosamente, David Rodrigues Em qua., 11 de nov. de 2020 =C3=A0s 14:59, Christoph M. Becker escreveu: > On 11.11.2020 at 18:39, Dan Ackroyd wrote: > > > On Tue, 10 Nov 2020 at 17:39, Hans Henrik Bergan > wrote: > >> > >> something i'm missing from Javascript is the ability to give names to > >> closures, ...the name is optional, and only visible inside the closure > >> itself, and unfortunately this is not legal in PHP, i wish it was. > > > > I really like that...but unfortunately that wouldn't work in PHP. > > > > In JS, when a function is declared inside another function, the name > > of it is limited to the scope of the containing function. In PHP, when > > a function is declared inside another function, it is put into the > > current namespace's global scope. > > > > Changing how scope works in PHP would be too large a change for just > this. > > In JavaScript, a named function expression is different to a function > declaration: > > var fn =3D function foo() {console.log('blah')} > foo() > =3D> Uncaught ReferenceError: foo is not defined > > vs. > > function foo() {console.log('blah')} > foo() > =3D> blah > > So the named function expression is still an anonymous function; the > label is only defined inside of the function body. > > Christoph > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --0000000000008470c105b3d91687--