# Permitting trailing commas in closure use() declarations

- Thread: https://externals.io/message/110715
- Original archive: https://news-web.php.net/php.internals/110715
- Started by tyson andre on 2020-06-24T15:22:51+00:00
- Messages: 3
- RFC: Allow trailing comma in closure use lists (Implemented (PHP 8.0)) — https://externals.io/rfc/trailing_comma_in_closure_use_list.md
- RFC: Allow trailing comma in parameter list (Implemented (PHP 8.0)) — https://externals.io/rfc/trailing_comma_in_parameter_list.md
- RFC: Trailing commas in list syntax (Implemented (PHP 7.2)) — https://externals.io/rfc/list-syntax-trailing-commas.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #110715 — tyson andre — 2020-06-24T15:22:51+00:00

URL: https://externals.io/message/110715#110715

Hi internals,

https://wiki.php.net/rfc/trailing_comma_in_parameter_list mentioned

> https://wiki.php.net/rfc/list-syntax-trailing-commas Trailing Commas In List Syntax was a previous proposal to support optional trailing commas in all list-like structures.
>
> Nothing has substantially changed since those RFCs in technical terms, but I think the aforementioned style > for breaking up large parameter lists has become more accepted in the meantime, and features like Constructor Property Promotion are going to increase its use further.

So I'm wondering if anyone's interested in revisiting this:

- It'd be easy to forget that function parameters support trailing commas, but not closure uses, especially if you're new to the language.
- Supporting trailing commas in multi-line declarations would make version control history easier
- if you had a closure for which `fn` wouldn't work (a list of values *and references* to use, or a list of statements),
  it'd be convenient to split it up across multiple lines

e.g. 

```
        $incrementing_id = 0;
        return \array_map(static function (array $map) use (
            $function,
            $some_data_structure,
            $some_flag,
            &$incrementing_id,
        ): ReturnType {
```

---

## #110716 — Ben Ramsey — 2020-06-24T15:25:03+00:00

URL: https://externals.io/message/110715#110716 · In reply to: #110715

> 
> 
> Hi internals,
> 
> https://wiki.php.net/rfc/trailing_comma_in_parameter_list mentioned
> 
> > […]
> 
> So I'm wondering if anyone's interested in revisiting this:
> 
> - It'd be easy to forget that function parameters support trailing commas, but not closure uses, especially if you're new to the language.
> - Supporting trailing commas in multi-line declarations would make version control history easier
> - if you had a closure for which `fn` wouldn't work (a list of values *and references* to use, or a list of statements),
>  it'd be convenient to split it up across multiple lines
> 
> e.g.
> 
> ```
>        $incrementing_id = 0;
>        return \array_map(static function (array $map) use (
>            $function,
>            $some_data_structure,
>            $some_flag,
>            &$incrementing_id,
>        ): ReturnType {
> ```


+1 for consistency with allowing trailing commas in all places like this.

Cheers,
Ben

---

## #110796 — Nikita Popov — 2020-07-01T07:39:07+00:00

URL: https://externals.io/message/110715#110796 · In reply to: #110715

On Wed, Jun 24, 2020 at 5:23 PM tyson andre <tysonandre775@hotmail.com>
wrote:

> Hi internals,
>
> https://wiki.php.net/rfc/trailing_comma_in_parameter_list mentioned
>
> > […]
> List Syntax was a previous proposal to support optional trailing commas in
> all list-like structures.
> > […]
> but I think the aforementioned style > for breaking up large parameter
> lists has become more accepted in the meantime, and features like
> Constructor Property Promotion are going to increase its use further.
>
> So I'm wondering if anyone's interested in revisiting this:
>
> - It'd be easy to forget that function parameters support trailing commas,
> but not closure uses, especially if you're new to the language.
> - Supporting trailing commas in multi-line declarations would make version
> control history easier
> - if you had a closure for which `fn` wouldn't work (a list of values *and
> references* to use, or a list of statements),
>   it'd be convenient to split it up across multiple lines
>
> e.g.
>
> ```
>         $incrementing_id = 0;
>         return \array_map(static function (array $map) use (
>             $function,
>             $some_data_structure,
>             $some_flag,
>             &$incrementing_id,
>         ): ReturnType {
> ```
>

Sounds reasonable to me. I thought we had already covered all cases that
are inside (), but apparently not.

I think if there are no objections on list, we can just land this change.
Given how positive the outcome of the "trailing comma in parameter lists"
RFC was this doesn't seem controversial.

Regards,
Nikita
