Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112224 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 73269 invoked from network); 11 Nov 2020 18:17:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Nov 2020 18:17:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D688F1804D9 for ; Wed, 11 Nov 2020 09:39:58 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) (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 09:39:58 -0800 (PST) Received: by mail-vs1-f43.google.com with SMTP id l22so1636501vsa.4 for ; Wed, 11 Nov 2020 09:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oe6Uxl+2hG+05ts7EdZHpRp29e56ZExhNa3SvFtIlpA=; b=gBnXFWzKa1pkpDT+CazjVLV7MC0hrjlFbITtrbA/CTuIavaO6DnT4qrOH+0mQc2MLd J0Tws6cyRbDa4GRLcxJSLznsEMs2eGoMNNIG6L68JjHnjT4eBSZUzHVTdDmD4zdK6XZZ s0XHh7O6BKfxuUHotNOJZ9wiRx0E8FsWVCSkOkD0KRH2DlA6+Njgd9ARLRmCBhptFX05 LcHF3dCDtsBzz6bV6qvJXBb6fioSZmk4D3V4ni/KQs4w1cs89I1hYPEYjw+Ur/b1g39z cW4P6laWXhlqMnU6b3Sy9XmgCUHTiQgaBvI/1YXkMX4y05x9Bll3dJBv1nJbJE5lEp/a DDJA== 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=oe6Uxl+2hG+05ts7EdZHpRp29e56ZExhNa3SvFtIlpA=; b=PZJGoyfMi9Gu/xpR9r9qMzwADC8onimNkaUhHIYjVsKz2yGmERgIqi7rbZSsdTY8jI uhw6S4IiNudiXU4uQwvB3qDHlBlW8383ANrobdGKddU0eT7Vtmo3BVHrwoef0DmAhmh+ jVF35ltU9qKZhiqZFDDj062xzc/a2nNX+pEEFVfNK2uAtVqvC0VlWdn3ztzajrVcmQGA wW4mTPovHh+SZo53IwjK6NTdjtNsBFxMkuHT7FflaP0PSLKWEYFeefXPGcKlhIH9XNiJ VzooJVdMKsw393hjzQjDRaBLQwF3/oiszdS4wKZBcOG/G6J1a8uUkynQ+Gw+Y5Oy4us1 ryrg== X-Gm-Message-State: AOAM531gwWGdmktHBpA+VOgVU7QBMKLzcqLTO7cslCtrzazJZPTMpwqi rPC9R/lJ6ppUWbWxRZbITJ+aZtJ6R12U9ZdiLlqDaQ== X-Google-Smtp-Source: ABdhPJxk6wQlrsIuphWgVnZ5oegv9Y12e9DK05+wEtaRaiIxFawSihChbMZSl2oGXAsJ/uxhGUTljH3UtSyMfNfA/IQ= X-Received: by 2002:a67:687:: with SMTP id 129mr16694980vsg.37.1605116396520; Wed, 11 Nov 2020 09:39:56 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 11 Nov 2020 17:39:44 +0000 Message-ID: To: Hans Henrik Bergan Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] Draft - Closure self reference From: Danack@basereality.com (Dan Ackroyd) 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. Levi Morrison wrote: > Is there any way we can spell it `__FUNCTION__`? I think using some sort of constant, rather than a magic variable sounds is probably the way to go. I would hope we could find something better than that as: return __FUNCTION__($n-1) + __FUNCTION__($n-2); is pretty hard on my eyes. I think I'll wander over to the 'Support for ::function syntax' thread... cheers Dan Ack # PHP function foo1() { function bar() {} } function foo2() { function bar() {} } foo1(); foo2(); // Fatal error: Cannot redeclare bar() # JS function foo1() { var fn = function TheClosuresLocalName(){ console.log("I am closure inside foo1"); } return fn; } function foo2() { var fn = function TheClosuresLocalName(){ console.log("I am closure inside foo2"); } return fn; } fn1 = foo1(); fn2 = foo2(); fn1(); fn2(); "I am closure inside foo1" "I am closure inside foo2"