The Pipe Operator

Read the RFC Externals
87
253 yes
119 no

The "pipe operator" |> allows you to chain multiple function calls in a more convenient way.

$result = "Hello World"
    |> 'htmlentities'
    |> 'str_split'
    |> fn($x) => array_map('strtoupper', $x)
    |> fn($x) => array_filter($x, fn($v) => $v != 'O');

This RFC was already declined, but we're sharing it here as another test RFC, and because it'd be interesting to learn people's opinion about it.

Click the bar to cast your vote!
68%
32%
1

I've long been a fan of the pipeline operator, it is such a minor syntax change that gets in the way of nothing, but allows for, in my opinion, a much cleaner and more readable set of procedural code where you can read naturally from top-to-bottom instead of middle-out.

Share:
liam avatar
liam
voted yes
1

Having used functional programming languages before, the pipe operator is immensely useful in performing transformation on a data structure in a nice and concise way, with minimal boilerplate needed.

Share:
askonomm avatar
askonomm
voted yes
1

I like the clean syntax. It would allow chaining items and removing the function within a function within a function that quickly becomes an ugly and confusing mess of code.

Share:
jim avatar
jim
voted yes
1

because is veri beutiful

Share:
pablohernandez avatar
pablohernandez
voted yes
1

I do not like the notation with the function names as string but apart from that I think it can make processing arrays and strings more painless.

Share:
alexander avatar
alexander
voted yes
1

I'm not really hot about this feature. It doesn't really add anything, it's just sugar syntax. We should use this operator for something else, way more complex that can't simply be emulated userland, and a simple function will do the same job that this RFC proposes.

On the other hand, if other popular languages have this, in that case I'll change my vote to Yes, I'm open-minded.

Share:
dorotheexplorer avatar
dorotheexplorer
voted no
1

This syntax is really not what PHP needs to be striving for. The idea is nice and SHOULD be revisited with cleaner and more modern syntax, but i'm against the proposal as it is presented right here.

Share:
simonvanacco avatar
simonvanacco
voted no
1

It makes the code more readable, isn't one of the things we all strive for ?

Share:
sidux avatar
sidux
voted yes
1

Great with RFC: First-class callable syntax

Share:
indigoram89 avatar
indigoram89
voted yes
1

Could make php more flexible language.

Share:
mcek avatar
mcek
voted yes
1

replace string function names with first class callables and my in!

Share:
ddruganov avatar
ddruganov
voted yes
1

Make the code more readable like elixir does.

Share:
semsphy avatar
semsphy
voted yes
1

Used pipe operators in Elixir lang and loved it. This will help make code more readable.

Share:
robindrost avatar
robindrost
voted yes
1

I like the proposition, but I would use some special "variable" ($$) for piped value (see v1 proposition: https://wiki.php.net/rfc/pipe-operator) so you don't have to use closures inside pipe to place value

$name = 'my_user_name'
	|> str_replace('_', ' ', $$)
	|> strtolower($$)
	|> ucwords($$)
	|> trim($$);

I don't like mapping function names as strings too

Share:
yoshi129 avatar
yoshi129
voted yes
1

That's awful, we see strings not function calls.

Share:
davg avatar
davg
voted no
RSS Feed Contribute Watch on YouTube Our License
© 2024 RFC Vote. This project is open source. Contribute and collaborate with us!