On 12/10/2017 22:32, Sara Golemon wrote:
> answer, but (Foo::class.'::bar') may be what some would expect.
> 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