On Fri, May 13, 2016 at 10:18 AM, François Laupretre <franc...@php.net> wrote:
>> So we'd have to audit all 4k+ functions in the PHP runtime (and
>> provide a mechanism for defining it on userspace functions)?
>
> That's right, except that, if we only consider functions accepting more than
> 1 arg, we just need to check about 1,000 functions. It may seem a lot but,
>
Having been a large part of the audit for PHP6, I'd say "Yes, it
definitely seems like a lot, and is." :p

> for a potential solution to such a long-time issue as argument ordering
> sadness, IMHO, it's worth the pain. I am currently doing it and I'll send
> you the list when it is ready.
>
Awesome.  Even if not used in this feature, it could potentially be
useful elsewhere.  I hope you put it in a public gist or similar for
posterity.

> For userspace functions, the logic can be quite simple : 0 arg -> not usable
> in a pipeline, 1 arg or more -> substitute first arg. Then, we have 4
> options :
>         - consider that, when using a userland function in a pipeline, the
> lhs is always inserted in 1st position,
>
It would feel weird that internal functions can deviate from this
rule, but user-space functions can't. :/

>         - provide a function to change the position on an existing function
> (default = 0 when function is registered). A negative position would disable
> using the function in a pipeline,
>
Feels like a hack, but I suppose if it were part of Reflection it
might make sense...

(new ReflctionFunction('my_func')->setPipeArgPosition(3);

>         - enrich the syntax of function declaration to designate the arg to
> substitute.
>
This would be a good application for User Attributes:

<<__PipeArg(1)>>  // Zero based, obv
function array_map(Callable $fn, array $arr) {...}


> I would propose to start with the 1st choice. After people have the occasion
> to use it for a while, we will see if an additional mechanism is requested.
>
That's not unreasonable if we're starting from a place of assuming
that invisible substitution is the way to go.  I'm not convinced, but
I could be.

Just to verify, you're suggesting an end-state something like this?

$ret = array(1,2,3)
  |> array_map(function($x) { return $x * 2; }) // lhs implicitly
passed as second arg
  |> array_sum(); // implicitly passed as only arg (first position)
// $ret === int(12)

-Sara

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to