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.
I don't like the example in the description, but with First-class callable syntax it looks better and more convenient.
Very good proposal but there are bad examples in RFC. RFC should not use strings as callable.
it's works great in other languages and has a better readability and clearer syntax.
I love this idea, but I loathe the syntax. However, I am not clever enough to propose another syntax. My issue with chaining by nesting functions is that it reads backwards, and that's just so visually messy that I end up just setting the variable multiple times for readability alone, which is the desired outcome anyway. It's not like we NEED to be terse in PHP to save a few bytes. Better to have obvious and readable code. So while I'm voting yes for this, it's for concept only, not crazy about the syntax. 🤷♀️
No benefit, it is also feels bad to use a function name as string when referencing it. Limited usefulness if the via-string-called-function has more than one argument.
its syntax is too much complicated
Could be nice, but like said by others without the function define using string
Much clearer than nesting multiple calls.
I like the idea, but I really don't like the proposed syntax. It looks like I'm reading a totally different language. I could get behind this if the syntax was prettier.
Using first-class callables, this addition would be so dope! 🔥
In general I would love to see this added to PHP
It would make it easier to debug a flow as well even without tools like XDebug because during development you would be able to insert a |> dd(...)
for instance
I did not like writing function names between quotation marks
for my part, I don't have any arguments except that I much prefer pipeline systems and not having long code like that... it's a question of readability
Such an awful RFC and people are voting for it 😱, weird. I agree with Rasmus Lerdorf, Nikita Popov and Sebastian Bergmann, this PR should NOT go into the language.
I think we should focus more on improving the performance and fixing things that people don't like in PHP rather than implementing new features.
We already have a solid language that does so many things for us, everything else is provided by frameworks. I understand why people want to see features like this one, but I would prefer to focus on the performance and cleaning up the codebase of PHP source code.
The language does not need this fancy tools, what we really need is better support for types, kinda like whats Typescript did for JS.
Interface Default Methods improves backwards compatibility when changing interfaces, but also add a way to have multi-inheritance in PHP.
Chain method on newly created objects without parentheses
A new syntax for declaring the “set” operation visibility of an object property