Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104737 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51347 invoked from network); 15 Mar 2019 13:12:20 -0000 Received: from unknown (HELO mail-it1-f176.google.com) (209.85.166.176) by pb1.pair.com with SMTP; 15 Mar 2019 13:12:20 -0000 Received: by mail-it1-f176.google.com with SMTP id o76so6159646ita.3 for ; Fri, 15 Mar 2019 03:02:56 -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 :cc; bh=9WprulsoHwXlR3oDfHOIUhVXqnKj90uVOcxfF08wX78=; b=C1MvC0GC8XEQ9ITDbfChK4GCo1DGJcSZS+S+0g8T3/skSN6unlbLb3KdFvXDWhj5PX eR38HSs2uN8mI/DDxCTXkO5BfBiydnZL1sjyTFofhJdwBbJxomDcTaFILzX1NLrECIQ7 JbWJAECNJ83MeLGYm1wx4m0QvFYmKZZJftZNlCwsHirZKc0KiKbAkI0ELDed2s72OEe9 DnU5tXbMdVdPp8xomqwDOhqhKmGcI+XGAIxlvbzWlCZF/wk90bjs7zsAm/WlzxWcSE8u lWnxJv4p/EWg+4T6QgcjISIYfl/24Z6V5o1J3fGQ36nh3HSVYOKnlJDVmX1dRytQAb8d /p3A== 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=9WprulsoHwXlR3oDfHOIUhVXqnKj90uVOcxfF08wX78=; b=nYyUfX7tr0er6yHWKuOMluoLA4qgIbFxrNY6U2pgurYUN+84xkraP+W7OWeJa7N81G SmcX60QjIXHDEujcxlK8VbRphacVKk+Pb/RkNyofo6z8Lkq2tZ1sfYehNMudsCi1Ot4v JqL3AIhQV+im/gOBIQE62CbcfWW+xUIVDmnqQ4UeBm5z35vF6qbwQHvkjsB0Q0tYBYmb PAKJSyLQp7rhSrvXRYr/OApOdK95tMuvFyZlciiJ9yeLWd7BFDxg08MMtNFzt2Ne6gtu /JSVMgHbf2iaadyGaF1YZjItoQiIxV54RQm+U4ExFQjqLMoM7tLg94kLo2H5zIFtsg1w 7uoA== X-Gm-Message-State: APjAAAUGDh8MMHvVbmoeJBzKNE2+S4f5RzCExR5DitIzODTK4V6Muz0O OMYB8vo+I9wwFEnzYkwbFN2koC3vIoI1g+eHozwBCxSA X-Google-Smtp-Source: APXvYqxl1xwK/JTThp8t0k96+ve5teJHuWxZQhtT7gwKC6bdKrGo1ck6HuSKzEp/HdyF3XCqJj8ZfukDv712SVlMN+U= X-Received: by 2002:a24:7542:: with SMTP id y63mr1445975itc.70.1552644175278; Fri, 15 Mar 2019 03:02:55 -0700 (PDT) MIME-Version: 1.0 References: <20190314140356.Horde.DRHws4diCrCqDCSv6NgOSdD@cloud.rochette.cc> In-Reply-To: <20190314140356.Horde.DRHws4diCrCqDCSv6NgOSdD@cloud.rochette.cc> Date: Fri, 15 Mar 2019 11:02:38 +0100 Message-ID: To: Mathieu Rochette Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000008807ac05841f245b" Subject: Re: [PHP-DEV] [RFC] Arrow functions / short closures From: nikita.ppv@gmail.com (Nikita Popov) --0000000000008807ac05841f245b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 14, 2019 at 3:04 PM Mathieu Rochette wrote: > > Hi, > > it's nice to see this going on again :) > > while reading the rfc I was wondering, why do we need the "static" > keyword, couldn't static function be detected automatically ? > I've added a note regarding this in https://wiki.php.net/rfc/arrow_functions_v2#this_binding_and_static_arrow_f= unctions. The problem is that in PHP we cannot actually reliably detect whether or not a closure uses $this. Sure -- we can see literal $this uses, but some of them are implicit: fn() =3D> Foo::bar() can make use of $this if $this is scope-compatible wit= h Foo. fn() =3D> call_user_func('Foo::bar') can as well. fn() =3D> $a($b) can= as well, if it so happens that $a =3D 'call_user_func' and $b =3D 'Foo::bar'. = The result is that we cannot reliably detect whether $this is used or not -- we can only make a conservative analysis that may sometimes bind $this even though it's not needed. In which case I would prefer going with the more predictable behavior of always binding $this, and using "static" in the rare cases where someone really cares about this. > I guess this apply to the existing closure syntax as well so to get more > on this topic I'll share my preferences on the syntax: I like the =3D=3D>= or ~> > version because it also allow to drop the parenthesis when there is only > one argument and it's closer to what I'm used to in javascript > > I wouldn't mind having the rust syntax too but yeah, it would feel a bit > odd in PHP > > > thank you for your work on this ! > > Nikita Popov =E2=80=93 Wed, 13. March 2019 16:57 > > Hi internals, > > > > Motivated by the recent list comprehensions RFC, I think it's time we > took > > another look at short closures: > > > > wiki.php.net/rfc/arrow_functions_v2 > > > > This is based on a previous (withdrawn) proposal by Levi & Bob. It uses > the > > syntax > > > > fn($x) =3D> $x * $multiplier > > > > and implicit by-value variable binding. This example is roughly > equivalent > > to: > > > > function($x) use($multiplier) { return $x * $multiplier; } > > > > The RFC contains a detailed discussion of syntax choices and binding > modes. > > > > Regards, > > Nikita > --0000000000008807ac05841f245b--