The "pipe operator"
|> allows you to chain multiple function calls in a more convenient way.
$result = "Hello World"
|> 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.
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.
This is another RFC that focuses on the Developer Experience of PHP and gets shutdown by internals because of bikeshedding or lack of interest in doing things for the sake of improving DX. The syntax allows for clear and concise code and goes hand-in-hand with First-party callable and short arrow functions. There aren't many things that can be expressed in a syntax, but this one can replace entire PHP libraries (kind of similar to PHP Enum) and make the entire pipeline process in PHP fluid and readable.
"Very good idea, but it would be nice to avoid using strings in the function calls."
Doesn't this proposal conflict with the Hack-like pipe operator where you can choose which argument to pipe into, using
$$? This is not necessarily a no-vote, just a listed concern. :)
Also, the examples should use
str_split(...) syntax, not strings, IMO.