Re: [RFC] Pipe Operator

From: Date: Tue, 17 May 2016 12:47:07 +0000
Subject: Re: [RFC] Pipe Operator
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  Groups: php.internals 
Request: Send a blank email to internals+get-93371@lists.php.net to get a copy of this message
On Tue, May 17, 2016 at 6:15 AM, François Laupretre <francois@php.net> wrote: > > > >> The question of function aliases is not so serious because we'll need very >>> few. Almost every functions have only one 'natural' argument to >>> substitute >>> as lhs. I'm not sure I understand what you mean with 'but only in certain >>> situations'. >>> >>> If it were so natural, wouldn't the original version of these >> functions have been made "right" in the first place? I fear that the >> only thing we'd gain by adding all these aliases is more functions, >> but without the benefit of any improvement in the argument ordering >> problem because now, instead of remembering which order the argument >> is in, users have to remember which alias to call. >> > > Right. That's why I propose we start without creating any function alias. > We're not supposed to allow writing anything in a pipeline. For every > functions, the substituted argument will always be the > haystack|subject|source|input argument. That's easy to remember. > Which I don't think covers many use cases that the Pipe Operator would currently solve. Doing this would lessen its usefulness IMO. Think about common string nesting like: $var = substr($var, 0, strpos($var, $othervar)); With current Pipe it would be: $var = strpos($var, $othervar) |> substr($var, 0, $$); but your suggestion requires this be kept nested as only haystack is allowed? That totally weakens the proposal in my book. @Sara: Can the place holder be used twice? If its numeric, can I make it negative or perform other math? I don't see anything in the RFC allowing or disallowing such things. Such as: $var = strlen($str) |> substr($var, -$$, $$/2)

« previous php.internals (#93371) next »