Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:100895 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92544 invoked from network); 13 Oct 2017 20:45:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Oct 2017 20:45:05 -0000 Received: from [127.0.0.1] ([127.0.0.1:1532]) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ECSTREAM id 30/C6-07885-1D521E95 for ; Fri, 13 Oct 2017 16:45:05 -0400 X-Host-Fingerprint: 5.67.70.161 054346a1.skybroadband.com Received: from [5.67.70.161] ([5.67.70.161:10421] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 11/E4-07885-29BC0E95 for ; Fri, 13 Oct 2017 10:20:03 -0400 Message-ID: <11.E4.07885.29BC0E95@pb1.pair.com> To: internals@lists.php.net References: Date: Fri, 13 Oct 2017 15:20:03 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Posted-By: 5.67.70.161 Subject: Re: [PHP-DEV] Suggestion Method Constant From: markyr@gmail.com (Mark Randall) On 12/10/2017 22:32, Sara Golemon wrote: > Ideally we'd have first-class references to functions. > -Sara To chime in.. To my mind, references to functions is the holy grail so far as beginning to clean up the entire ecosystem around function calls. IMHO directly referencing MyClass::StaticFunction eventually needs to return a "Function" class that is directly invokable. I see 3 contexts that the parser would need to handle: 1. Standard Calling MyClass::StaticFunction(1, 2, 3); my_function(1, 2, 3) $inst->my_function(1234); Obviously returning a full function object to useland for every call would be considered wasteful, so the parser would need to call these as before. 2. Returning a native "Function" class, an __invokeable hybrid of Callable and Reflection; $method = MyClass::StaticFunction; $method(1, 2, 3); $method = $inst->my_function; /* bind to $inst */ $method(1, 2, 3); $method->getName(); $method->getArgumentCount(); $method->getBinding(); 3. Returning closures when the argument list includes one or more late-bound values, so we can finally put the pipe operator to bed at the same time as getting a bunch of other power from it. $method = MyClass::StaticFunction($1, 'Arg 1', 'Arg 3); $method('Arg 1'); $method = $inst->my_function('Arg 1', 'Arg 2', $1); $method('Arg 3'); chain( 'Random String', func_1($1, 'Hello', 'World'), func_2($1, 'Peace', 'Out'), func_3('ThisOneNeeds', 'Arg3ReplacingInstead', $1), func_3($1, $1, 'HowAboutOneWhichUsesTheSameArgumentTwice') ); function chain($start, ... $fns) { foreach ($fns as $fncall) { $start = $fncall($start); } return $start; } -- Mark Randall