# [RFC][Discuss] Arrow Functions

- Thread: https://staging.externals.io/message/98066
- Original archive: https://news-web.php.net/php.internals/98066
- Started by Ilija Tovilo on 2017-01-31T09:32:31+00:00
- Messages: 1
- RFC: Arrow Functions (Obsolete) — https://staging.externals.io/rfc/arrow_functions.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://staging.externals.io/search.md?q={query} · RFCs at https://staging.externals.io/rfc.md · JSON API at https://staging.externals.io/api · documentation at https://staging.externals.io/llms.txt

---

## #98066 — Ilija Tovilo — 2017-01-31T09:32:31+00:00

URL: https://staging.externals.io/message/98066#98066

I agree. Using the prefix `function` kind of defeats the purpose of the whole RFC.

There are three things that contribute to the boilerplate of closures:



- The `function` keyword

- The `return` keyword

- The `use` clause



The RFC eliminates two and reduces one to about 25%.



I also dislike the idea to use `fn($x, $y => $x + $y)` kind of syntax for two reasons:



1. To anyone who knows arrow functions fron any other language, this looks like a function call

2. Optically, `$x` and `$y => $x + $y` look like separate parameters


Also, as mentioned in the RFC adding the `fn` keyword only has very minor backwards compatibility issues.



Regards,

Ilija








Bob Weinand and I are happy to announce that the [Arrow Functions][1]
RFC is moving into the public discussion phase. We have been
collaborating on this RFC for many months now and finally have a
proposal we are happy to discuss in the open.


Here is an example of an existing closure:


function ($x) use ($arr) {
return $arr[$x];
}


This RFC proposes syntax and semantics to simplify this common usage to:


fn($x) => $arr[$x]


More details are in the RFC. The [implementation][2] currently has no
known issues and is ready for you to download, build and test, which
we encourage you to do.


We look forward to a productive discussion period and are happy to
answer questions.


For historical purposes, the revision of this RFC is currently at
[1485798604][3].


[1]: https://wiki.php.net/rfc/arrow_functions

[2]: https://github.com/morrisonlevi/php-src/tree/arrow_functions

[3]: https://wiki.php.net/rfc/arrow_functions?rev=1485798604


Hey Levi, Bob,

that looks very good.

The fn prefix is peculiar yes but it's alright, it doesn't harm neither
readability nor writability, it even has some precedences in other
languages (think Rust, Elixir) and as we all know it is necessary for
parser.

Thanks for the work, I hope it lands in PHP.
