The Pipe Operator

Read the RFC Externals
92
268 yes
130 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!
67%
33%
1

Very good proposal but there are bad examples in RFC. RFC should not use strings as callable.

Share:
raszekster avatar
raszekster
voted yes
1

it's works great in other languages and has a better readability and clearer syntax.

Share:
jeidison avatar
jeidison
voted yes
1

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. 🤷‍♀️

Share:
jklmnop avatar
jklmnop
voted yes
1

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.

Share:
dsentker avatar
dsentker
voted no
1

its syntax is too much complicated

Share:
emreakay avatar
emreakay
voted no
1

Could be nice, but like said by others without the function define using string

Share:
jarbey avatar
jarbey
voted yes
1

Much clearer than nesting multiple calls.

Share:
przemyslaw avatar
przemyslaw
voted yes
1

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.

Share:
thomasalrek avatar
thomasalrek
voted no
1

Using first-class callables, this addition would be so dope! 🔥

Share:
zois avatar
zois
voted yes
1

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

Share:
Carakas avatar
Carakas
voted yes
1

I did not like writing function names between quotation marks

Share:
tasarsu avatar
tasarsu
voted no
1

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

Share:
grazulex avatar
grazulex
voted no
1

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.

Share:
Contributor serhii avatar
serhii
voted no
1

The language does not need this fancy tools, what we really need is better support for types, kinda like whats Typescript did for JS.

Share:
isaacsouza avatar
isaacsouza
voted no
1

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.

Share:
marco avatar
marco
voted yes

Check out another RFCs

Interface Default Methods

Interface Default Methods improves backwards compatibility when changing interfaces, but also add a way to have multi-inheritance in PHP.

95
168 yes
264 no
new MyClass()->method() without parentheses

Chain method on newly created objects without parentheses

45
74 yes
15 no
Short Closures 2.0

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.

101
373 yes
66 no
RSS Feed Contribute Watch on YouTube Our License
© 2024 RFC Vote. This project is open source. Contribute and collaborate with us!