On Tue, Sep 19, 2017 at 4:32 PM, Sara Golemon <poll...@php.net> wrote: > I was planning to update the RFC, but wiki.php.net is having issues > atm and isn't coming back up with basic coaxing, so I'll just start > discussion informally, and the RFC can be updates later. > > Background: I made an RFC some time ago to implement HackLang's Pipe > Operator https://docs.hhvm.com/hack/operators/pipe-operator which > provides fluent calling for non-object interfaces. > I circulated it to mixed reviews, many negative, with the negativity > feeling like it centered on the use of a magic placeholder token `$$`. > > After discussion with Levi and others who suggested a simpler > approach, I'd like to offer > https://github.com/php/php-src/compare/master...sgolemon:pipe2 as an > alternate possibility. > > This version removes the $$ token, and instead treats the RHS of the > expression as a callable obeying the same rules as the callable > typehint elsewhere in the language. Specifically: > * Free functions as strings containing the function name. (e.g. 'funcname') > * Object methods as array($object, 'methodname') > * Static methods as array('Classname', 'methodname') > * Closure expression (e.g. function($x) { return ...; } ) > * Object instance with an __invoke() method. > > In a given pipe expression, the output of the LHS expression feeds a > single arg to the callable on the RHS. > Examples: > > $x = "hello" > |> 'strtoupper' > |> function($x) { return $x . " world"; }; > // $x === "HELLO world" > > Non-Goal: I didn't include support for base function names (e.g. > `"hello" |> strtoupper`) because of the conflict with constants. > Using a constant to store your function name is totes legit and > consistent with language syntax. > > Future Scope: Short Lambdas `$x => $x + 1` and Partial Functions > `someFunc('fixed val1', ..., 'fixed val2')` would help make this > functionality more useful and are worth discussing as a sub-thread, > but are not required to be implemented at the same time. > > -Sara > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php
Thank you for making this proposal! As alluded to I had concerns on the original proposal and fully support this version. Sometimes simplicity is the mark of a good RFC and I think this is one of those times. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php