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.
This doesn't appear in any popular language and does not bring any benefit to readability.
this actually looks not pretty
I think it's a very nice way to simplify code. For me it looks readable and cleaner without the need of creating temporal variables.
It's not crucial, but it's gonna make code more readable and clear in a way. But It would be even greater if we had literals for passing functions instead of strings, (e.g. |> htmlentities(...) instead of |> 'htmlentities').
The new syntax is noisy. It adds more cognitive load to the currently available function invocation methods.
The existing libraries supporting pipelining do it fine without extending the language syntax.
PHP is well known for "historic growth", i.e. internal functions often may return false instead of throwing an exception. I feel that using syntactic sugar to allow to travel the "optimistic path" (simply assuming the involved functions do not return false) is a bad idea.
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.
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.
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.
because is veri beutiful
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.
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.
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.
It makes the code more readable, isn't one of the things we all strive for ?
Great with RFC: First-class callable syntax
A new syntax for declaring the “set” operation visibility of an object property
This RFC proposes a way to have multi-line short closures — closures that don't need explicit use
statements, but can still have multiple lines and a return statement.