Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:76356 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1233 invoked from network); 5 Aug 2014 15:20:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Aug 2014 15:20:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=ralph@ralphschindler.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ralph@ralphschindler.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain ralphschindler.com from 209.85.219.43 cause and error) X-PHP-List-Original-Sender: ralph@ralphschindler.com X-Host-Fingerprint: 209.85.219.43 mail-oa0-f43.google.com Received: from [209.85.219.43] ([209.85.219.43:47723] helo=mail-oa0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 13/74-48163-A36F0E35 for ; Tue, 05 Aug 2014 11:20:26 -0400 Received: by mail-oa0-f43.google.com with SMTP id i7so790139oag.16 for ; Tue, 05 Aug 2014 08:20:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=qEpqzLb+8juD0uMnJeLQfBRVaKn84JeidynfqxajeKM=; b=b0EKQ8fHR3e3TZSNrIw81Nm7dIZCowcTsp2CppfolFrPYr9TdWhu0Xae+eLarBQ397 iZKKlCDUOXW7itPNDrQFA7SCNuuHj6Ct9/goXe7vrpSZgGKSpOHXK+5gSsipSoG/TlKv hEPeYe5FLyphGP0HGewAvweGTRAu243FRGgg08tEfFm4jp2/tEuaNw6A6Yxl8rPynGJr tz1aXJKk615mhjqbL1c99/CV+zp6IaJ7vSLe+UDhOPQ4jcKxCsNJJo0FZ36nLXjSTF7J pgLGIlVKqT3jnG2xIyo1uhFuca+QyPbczIFt1lcnbmvurQuCDxrquS5lZrhduiBP/PjX QrFQ== X-Gm-Message-State: ALoCoQkF3ewRTqqbBocNQskd4Qb3cGojNWVRXgiGVCqyYxlWcn4ak7nb07Zao2ohvZLOtYrZ4hQL X-Received: by 10.182.200.198 with SMTP id ju6mr6442135obc.1.1407252051391; Tue, 05 Aug 2014 08:20:51 -0700 (PDT) Received: from [172.16.1.120] (ip174-73-14-247.no.no.cox.net. [174.73.14.247]) by mx.google.com with ESMTPSA id h1sm8252873oem.5.2014.08.05.08.20.50 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 05 Aug 2014 08:20:50 -0700 (PDT) Message-ID: <53E0F651.1020101@ralphschindler.com> Date: Tue, 05 Aug 2014 10:20:49 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Closure::call and Function Referencing as Closures From: ralph@ralphschindler.com (Ralph Schindler) Andrea + Marco > 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. I like the proposal, but with some modifications. I am unsure if there is another RFC out there on function de-referencing, but at current the following is not possible: $x = function() { return function () { echo 'hi'; }; }; $x()(); Nor is de-referencing of a closure assigned to an object property: class Foo { public $bar; } $f = new Foo; $f->bar = function () { echo 'hi'; }; $f->bar(); While those are less important on their own, the use case that this does address is the ability to inline call a closure assigned to an object(/or class) property and fluently without call_user_func: class Foo { public $bar; } $f = new Foo; $f->bar = function () { echo 'hi'; return function () { echo ' world'; }; }; call_user_func(call_user_func($f->bar)); "->call()" would facilitate the following syntax, which I'd argue has greater semantic meaning than the call_user_func() variant: $f->bar->call()->call(); Additionally, the above assumes the following modification to the RFC: the additional of bindCall(), or something similarly named. The purpose here is to be able to call(/* args */) an existing closure with the current bound context (as a result from a previous bindTo) and bindCall($context, /* args */); to support the bind-and-call workflow. The reason for call() to operate on existing bound context would be this workflow: class Foo { public $bar; public function registerBar(\Closure $c) { // bind to specific scope as per Foo's specifications $this->bar = $c->bindTo(...); } } $f = new Foo; $f->registerBar(function () { echo 'hi'; return function () { echo ' world'; }; }); $f->bar->call(); // if you must change context: $f->bar->bindCall($otherContext); Thanks, Ralph Schindler