Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76334 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65832 invoked from network); 4 Aug 2014 12:27:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Aug 2014 12:27:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=ocramius@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ocramius@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.54 as permitted sender) X-PHP-List-Original-Sender: ocramius@gmail.com X-Host-Fingerprint: 209.85.192.54 mail-qg0-f54.google.com Received: from [209.85.192.54] ([209.85.192.54:55812] helo=mail-qg0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/13-46246-94C7FD35 for ; Mon, 04 Aug 2014 08:27:53 -0400 Received: by mail-qg0-f54.google.com with SMTP id z60so8956057qgd.27 for ; Mon, 04 Aug 2014 05:28:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=KVljF6z1WJTDny8nmtiax+FBQO4P0ZMO+MbSs0Hc1W8=; b=WDqPu7wnhlH33+Q6KtBgwGH9mWLXrL+LpAkB3B0/5iZB39h6JFAc93OPi0DxjxTFeD lhMX/4m+LdIVS3pGOeIAREo5ISOi8d5Z0+nwhJvDmB/zoPHRF604XAYejexYRDuGbUbJ oK6eVtgOU8YBvwJIQiVnSQ38iwRMpVAWeHBvwSwt+fPnLKVJiFFOPsBl4E+xBpFlfaSr F4S7DLN9ZBunl4KMST0Dk3xoHjkn+cVFnFmT8fBGQkWOCwjG/TQylRx8GkK9zc2iwbDx 5+PCKjriZ4FCuifOgo1AwiteHbLXVIuD3YWfdIzOJbEsQz37adikvbDK5V5Pp9H1MIbZ C/Sw== X-Received: by 10.140.98.118 with SMTP id n109mr22527740qge.47.1407155297261; Mon, 04 Aug 2014 05:28:17 -0700 (PDT) MIME-Version: 1.0 Received: by 10.140.18.230 with HTTP; Mon, 4 Aug 2014 05:27:57 -0700 (PDT) In-Reply-To: <06F3EF08-21B1-49AD-9D9D-5043C69AC1D8@ajf.me> References: <53DF2BED.10103@sugarcrm.com> <06F3EF08-21B1-49AD-9D9D-5043C69AC1D8@ajf.me> Date: Mon, 4 Aug 2014 14:27:57 +0200 Message-ID: To: Andrea Faulds Cc: Stas Malyshev , Nikita Nefedov , PHP internals Content-Type: multipart/alternative; boundary=001a113a48dea3223504ffccdf09 Subject: Re: [PHP-DEV] [RFC] Closure::call and Function Referencing as Closures From: ocramius@gmail.com (Marco Pivetta) --001a113a48dea3223504ffccdf09 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 4 August 2014 14:11, Andrea Faulds wrote: > On 4 Aug 2014, at 12:36, Marco Pivetta wrote: > > > Is the advantage of `Closure#call()` only performance? Because I don't > see other advantages otherwise, and I don't think the performance impact = is > relevant. > > There is a performance advantage which I=E2=80=99m going to test at some = point, > but that=E2=80=99s not why I propose adding it. It is to simplify binding= closures. > It=E2=80=99s not an uncommon operation to want to bind at call-time in ot= her > languages, and it can be useful. The fact that I'm arguing about is "yet another method to maintain" for an API that can simply live in userland (and is easier to maintain/upgrade/etc)... Unless there's a huge overhead, I don't see a problem with creating new closures: I do a lot of performance-sensitive stuff with `Closure::bind()` and I don't see how this API could help me. > > As for the function referencing RFC, I like it, but it is an annoying > syntax that seems to have been built just to accomodate the parser, and > that can be worked around in userland with overhead and more typing: > > > > $functionReference =3D function ($param) { return functionName($param);= }; > > That doesn=E2=80=99t work properly for class methods, both instance and s= tatic. It > doesn=E2=80=99t even work properly for normal functions, as you=E2=80=99r= e stripping away > parameter information. > Why do you actually need parameter information here? Starting from PHP 5.6, dynamic parameters can be passed on via variadics anyway. By-ref and by-val is also no big deal as well. This kind of call can be recognized by static analyzers, and can be refactored by IDEs. > > A syntax that I'd like, and which is IMO BC compatible would > be`::function`: > > > > array_map(count::function, [[1, 2], [3, 4]]); > > > > This is also very similar and similarly readable to what we have right > now with PHP 5.5 through the `::class` meta-constant. > > There's also no way to use `function` as a constant anywhere, so it > should be safe to use that right now. > > That syntax isn=E2=80=99t doable in the parser and isn't backwards-compat= ible > anyway. Classes and functions share the same namespace, so what do you do > when I have a class called FooBar and a function called FooBar? FooBar::methodName::function vs FooBar::function - clear and simple IMO. Consider http://3v4l.org/SY6vD, http://3v4l.org/YuMZ2 and http://3v4l.org/9ZRFN > How about if I have a class with a constant named function? Not allowed by the language > How do you propose to implement this pseudo-class system where functions > act like classes in only one case, when fetching this fake class constant= ? I'm not: `::function` is not a constant, it would be recognized by the parser directly. > How do you deal with the fact that constants cannot (with very good > reason) be objects? Not sure what you mean with this.. Marco Pivetta http://twitter.com/Ocramius http://ocramius.github.com/ --001a113a48dea3223504ffccdf09--