# [RFC] Allow trailing comma in function call argument lists

- Thread: https://externals.io/message/65931
- Original archive: https://news-web.php.net/php.internals/65931
- Started by Sara Golemon on 2013-02-19T12:06:53+00:00
- Messages: 65
- Page 1 of 3: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/65931.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #65931 — Sara Golemon — 2013-02-19T12:06:53+00:00

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

Opening RFC to allow trailing comma in function call argument lists

https://wiki.php.net/rfc/trailing-comma-function-args

---

## #65932 — Derick Rethans — 2013-02-19T12:10:28+00:00

URL: https://externals.io/message/65931#65932 · In reply to: #65931

> Opening RFC to allow trailing comma in function call argument lists
> 
> https://wiki.php.net/rfc/trailing-comma-function-args

+1

cheers,
Derick

---

## #65933 — Pierre Joye — 2013-02-19T12:20:06+00:00

URL: https://externals.io/message/65931#65933 · In reply to: #65931

> Opening RFC to allow trailing comma in function call argument lists
>
> https://wiki.php.net/rfc/trailing-comma-function-args

looks good and consistent enough, you have my vote :)


-- 
Pierre

@pierrejoye

---

## #65934 — Patrick ALLAERT — 2013-02-19T12:20:59+00:00

URL: https://externals.io/message/65931#65934 · In reply to: #65931

2013/2/19 Sara Golemon <pollita@php.net>:
> Opening RFC to allow trailing comma in function call argument lists
>
> https://wiki.php.net/rfc/trailing-comma-function-args
>
> --
> 
> 

I'm all for it! Waiting for the official voting...

---

## #65935 — Kingsquare.nl - Robin Speekenbrink — 2013-02-19T12:41:29+00:00

URL: https://externals.io/message/65931#65935 · In reply to: #65931

Just a question from one of the lingering listeners: would this change also
ease the `skipping` of default values for parameters? (as discussed for RFC
https://wiki.php.net/rfc/skipparams)

That way it would be consistent with this RFC and the list() construct ?

With regards,

Robin Speekenbrink


2013/2/19 Sara Golemon <pollita@php.net>

> Opening RFC to allow trailing comma in function call argument lists
>
> https://wiki.php.net/rfc/trailing-comma-function-args

---

## #65937 — Marcello Duarte — 2013-02-19T12:57:16+00:00

URL: https://externals.io/message/65931#65937 · In reply to: #65935

Inspired by Sara, here is another RFC, I finally got around to draft:

https://wiki.php.net/rfc/short-syntax-for-anonymous-function

Please feedback,
--
Marcello Duarte

---

## #65936 — Sara Golemon — 2013-02-19T13:00:42+00:00

URL: https://externals.io/message/65931#65936 · In reply to: #65935

On Tue, Feb 19, 2013 at 4:41 AM, Kingsquare.nl - Robin Speekenbrink
<robin@kingsquare.nl> wrote:
> Just a question from one of the lingering listeners: would this change also
> ease the `skipping` of default values for parameters? (as discussed for RFC
> https://wiki.php.net/rfc/skipparams)
>
> That way it would be consistent with this RFC and the list() construct ?
>
It's orthogonal to skipparams.  It'd neither help nor hurt based on
the recommendations of that RFC.

With regard to list(), it already supports expressions like this:
list($x,) = array(123); so nothing more needs to be done for it and
it's not at odds with either of these RFCs.

-Sara

---

## #65939 — Derick Rethans — 2013-02-19T13:19:21+00:00

URL: https://externals.io/message/65931#65939 · In reply to: #65937

> Inspired by Sara, here is another RFC, I finally got around to draft:
> 
> https://wiki.php.net/rfc/short-syntax-for-anonymous-function

I'd be really reluctant to add this -- it's yet another (superfluous) 
syntactical sugar, there is no patch, and how does this work with bound 
variables (use keyword)?

cheers,
Derick

---

## #65940 — Anthony Ferrara — 2013-02-19T13:20:55+00:00

URL: https://externals.io/message/65931#65940 · In reply to: #65937

Marcello,




> Inspired by Sara, here is another RFC, I finally got around to draft:
>
> https://wiki.php.net/rfc/short-syntax-for-anonymous-function
>
> Please feedback,
> --
> Marcello Duarte
>
>
I like the concept. I dislike the syntax. It looks too much like a JSON
object declaration, and it feels like it should be returning an object
instead of a closure/anonymous function. Additionally, I don't like that
it's also a closure. Short functions like this should be for simple
functions...

Perhaps:

lambda $x: trim($x);

$x: trim($x);

Or something similar...

Anthony

---

## #65941 — Michael Wallner — 2013-02-19T13:21:02+00:00

URL: https://externals.io/message/65931#65941 · In reply to: #65937

> Inspired by Sara, here is another RFC, I finally got around to draft:
>
> https://wiki.php.net/rfc/short-syntax-for-anonymous-function
>
> Please feedback,
>
>
Duh, I don't think function(){} is long.


-- 
Regards,
Mike

---

## #65942 — Paul Dragoonis — 2013-02-19T13:22:26+00:00

URL: https://externals.io/message/65931#65942 · In reply to: #65940

I also am not in favour of the syntax, it's too short and quirky. I'm
honestly fine with 'function()' it's very explicit


On Tue, Feb 19, 2013 at 1:20 PM, Anthony Ferrara <ircmaxell@gmail.com>wrote:

> Marcello,
>
>
> On Tue, Feb 19, 2013 at 7:57 AM, Marcello Duarte <mduarte@inviqa.com>
> wrote:
>
> > […]
> I like the concept. I dislike the syntax. It looks too much like a JSON
> object declaration, and it feels like it should be returning an object
> instead of a closure/anonymous function. Additionally, I don't like that
> it's also a closure. Short functions like this should be for simple
> functions...
>
> Perhaps:
>
> lambda $x: trim($x);
>
> $x: trim($x);
>
> Or something similar...
>
> Anthony

---

## #65944 — Patrick ALLAERT — 2013-02-19T13:28:05+00:00

URL: https://externals.io/message/65931#65944 · In reply to: #65937

2013/2/19 Marcello Duarte <mduarte@inviqa.com>:
> Inspired by Sara, here is another RFC, I finally got around to draft:
>
> https://wiki.php.net/rfc/short-syntax-for-anonymous-function
>
> Please feedback,
> --
> Marcello Duarte

BC break detected:

<?php
{
    echo "foo\n";
    return "bar";
};

echo "baz\n";
return 42;
?>

The {} would probably be a closure that is not assigned to anything
while the current behaviour is to print "foo" and exit while returning
"bar".

-1 since it only saves 10 chars ("function()") without real added value.

---

## #65946 — Bob Weinand — 2013-02-19T13:34:25+00:00

URL: https://externals.io/message/65931#65946 · In reply to: #65937

Hi,

I don't really like to write every time a "long" 'function()', only for passing a little callback like 'function ($v) { var_dump($v); }'...:

Nice proposal, but writing the last argument outside of the function call could be confusing... An user-function is not a language construct (like while etc.)

regards,
Bob

Am 19.2.2013 um 13:57 schrieb Marcello Duarte <mduarte@inviqa.com>:

> Inspired by Sara, here is another RFC, I finally got around to draft:
> 
> https://wiki.php.net/rfc/short-syntax-for-anonymous-function
> 
> Please feedback,
> --
> Marcello Duarte

---

## #65948 — Kingsquare.nl - Robin Speekenbrink — 2013-02-19T13:43:50+00:00

URL: https://externals.io/message/65931#65948 · In reply to: #65936

Sara,

I wasnt commenting that this RFC was different, just in agreement that this
syntax is _more_ in line with the list() construct (which then might
reflect the skipparams rfc))
If i wasnt clear: from a user point of view: i am all for this RFC ;)

Met vriendelijke groet,

Robin Speekenbrink
Kingsquare BV


2013/2/19 Sara Golemon <pollita@php.net>

> On Tue, Feb 19, 2013 at 4:41 AM, Kingsquare.nl - Robin Speekenbrink
> <robin@kingsquare.nl> wrote:
> > […]
> also
> > […]
> RFC
> > […]
> It's orthogonal to skipparams.  It'd neither help nor hurt based on
> the recommendations of that RFC.
>
> With regard to list(), it already supports expressions like this:
> list($x,) = array(123); so nothing more needs to be done for it and
> it's not at odds with either of these RFCs.
>
> -Sara

---

## #65949 — Florin Razvan Patan — 2013-02-19T13:46:05+00:00

URL: https://externals.io/message/65931#65949 · In reply to: #65937

Hello,


> Inspired by Sara, here is another RFC, I finally got around to draft:
>
> https://wiki.php.net/rfc/short-syntax-for-anonymous-function
>
> Please feedback,
> --
> Marcello Duarte
>

I really don't like syntax for this. It makes it hard to follow. Removing
a couple of characters while making the syntax harder to follow isn't
a good thing imho.

Also it's a BC break, like Patrick mentioned.


Have a nice day,
Florin
----
Florin Patan
https://github.com/dlsniper

---

## #65950 — Marcello Duarte — 2013-02-19T13:51:19+00:00

URL: https://externals.io/message/65931#65950 · In reply to: #65939

Thanks for the feedback. I get most people here don't appreciate the value of the feature.

I can understand that If you haven't tried to write a tool like capistrano, rspec, chef, puppet, etc, etc in PHP you probably won't see much value in implementing such things.


> 
> 
> > […]
> 
> I'd be really reluctant to add this -- it's yet another (superfluous) 
> syntactical sugar, there is no patch, and how does this work with bound 
> variables (use keyword)?

I added an example with the use keyword.

What is superfluous for is useful for other users. It would be useful building DSL. At my company we use loads of ruby tools for deploying, provisioning, etc. just because of the DSL they provide. The array short syntax was great news. Adding a short syntax for closures would make it possible to write such scripts in PHP – where the syntax would not stand on its way.


> > […]


I am actually more concerned with Patrick's feedback regarding BC. I can't think of a solution for this right now.

> cheers,
> Derick
> 
> -- 
> 
> 
> 

--
Marcello Duarte

---

## #65952 — Lars Strojny — 2013-02-19T13:56:15+00:00

URL: https://externals.io/message/65931#65952 · In reply to: #65950

Hi Marcello,

Am 19.02.2013 um 14:51 schrieb Marcello Duarte <mduarte@inviqa.com>:

> Thanks for the feedback. I get most people here don't appreciate the value of the feature.
> 
> I can understand that If you haven't tried to write a tool like capistrano, rspec, chef, puppet, etc, etc in PHP you probably won't see much value in implementing such things.
> 
> 
> > […]

I don’t like the syntax, but the proposal in general. If you compare PHPs syntax to various others, it is indeed clumsy.

Python:
map(lambda v: v * 2, [1, 2, 3])

Ruby:
[1, 2, 3].map{|x| x * 2}

Scala:
List(1, 2, 3).map((x: Int) => x * 2)

PHP:
array_map(function ($x) {return $x * 2;}, [1, 2, 3]);

So even a statically typed language like Scala is shorter and better to read. A good improvement would be implicit return and getting rid of the function keyword.

array_map(($x): $x * 2;, [1, 2, 3]);

But this RFC should come with a patch, otherwise we are discussing things that aren’t necessarily easy to implement.

cu,
Lars

---

## #65954 — Leigh — 2013-02-19T14:16:48+00:00

URL: https://externals.io/message/65931#65954 · In reply to: #65950

>
>
> I can understand that If you haven't tried to write a tool like
> capistrano, rspec, chef, puppet, etc, etc in PHP you probably won't see
> much value in implementing such things.
>
>
Your RFC doesn't go to great lengths to explain the value either. Pretend
the reader has no experience with any of those tools you mention, pretend
the only language they know is PHP, please explain where the value for this
syntax is in PHP?

I find the existing syntax easy to understand. I find the proposed syntax
disproportionally difficult and unintuitive in relation to any benefit it
is supposed to give.


> What is superfluous for is useful for other users. It would be useful
> building DSL. At my company we use loads of ruby tools for deploying,
> provisioning, etc. just because of the DSL they provide. The array short
> syntax was great news. Adding a short syntax for closures would make it
> possible to write such scripts in PHP – where the syntax would not stand on
> its way.
>
>
<insert PHP is not Ruby rhetoric>

If Ruby is the right tool for the job, and PHP is not the right tool for
the job, the answer to which language to use seems obvious right?

I disagree wholeheartedly that this proposed syntax would make code in any
way more readable, or maintainable.

---

## #65955 — Arvids Godjuks — 2013-02-19T14:44:38+00:00

URL: https://externals.io/message/65931#65955 · In reply to: #65954

I also don't like the RFC proposed syntax. I have to say that I don't
really like those short magic-like syntax things in in other languages too.
If you work with them on the day-to-day basis and tools are built around
those concepts - it's one thing. In PHP syntax is mostly self-explanatory
and for the most part there is only one way to do it (or the differences in
syntax have their own uses - like for () {} is used in code and  for ():
endfor; is good for templates).

I like the current $x = function () {}. It's the same in JavaScript (and
because most of us use jQuery - we use it a lot) and realistically I don't
type it - IDE does auto-complete for me.

P.S. I want to tell all those syntax enhancement guys - don't push
syntax-sugar stuff into PHP for the sake of shorter syntax. First, for the
most part it looks alien in PHP. Second - it really depends on the
preception - I for example hate Ruby syntax, it's crap and unreadable -
this just illustrated that's one mans beauty is other mans ugly. PHP syntax
maybe not the most pretty out there, but it is sure as hell easy to read
even if coder makes a mess of it. I saw the opinion on the internet that
PHP is a scripted version of C in the sense of their positioning and usage.
And I totally agree with it, and I want it to stay that way. PHP should not
be the pretty one, or be on the feature edge. PHP needs to just walk with
time and adopt the good stuff fully integrating into itself, not just
patching the core and adding some half-weird syntax that just doesn't
really fit PHP.
You also have to remember that PHP is a WEB development script language,
not general purpose script language like Ruby or Python. Not all features,
that are good in general purpose languages, are good for WEB language. Some
of those features may bring performance hits that are not worth it.

My 0.02$,
Arvids.

---

## #65956 — Cyberspice — 2013-02-19T15:13:00+00:00

URL: https://externals.io/message/65931#65956 · In reply to: #65931

> Opening RFC to allow trailing comma in function call argument lists
> 
> https://wiki.php.net/rfc/trailing-comma-function-args

+1

Melanie

---

## #65957 — guilhermeblanco@gmail.com — 2013-02-19T15:36:45+00:00

URL: https://externals.io/message/65931#65957 · In reply to: #65956

+1
 

> 
>
> > […]
>
> +1
>
> Melanie

---

## #65958 — Pierrick Charron — 2013-02-19T15:38:04+00:00

URL: https://externals.io/message/65931#65958 · In reply to: #65931

+1



> Opening RFC to allow trailing comma in function call argument lists
>
> https://wiki.php.net/rfc/trailing-comma-function-args

---

## #65959 — Will Fitch — 2013-02-19T15:40:21+00:00

URL: https://externals.io/message/65931#65959 · In reply to: #65936

> On Tue, Feb 19, 2013 at 4:41 AM, Kingsquare.nl - Robin Speekenbrink
> <robin@kingsquare.nl> wrote:
> > […]
> It's orthogonal to skipparams.  It'd neither help nor hurt based on
> the recommendations of that RFC.
> 
> With regard to list(), it already supports expressions like this:
> list($x,) = array(123); so nothing more needs to be done for it and
> it's not at odds with either of these RFCs.

I would vote +1 on this solely for the sake of consistency.  I've never liked the idea behind the parser's actions on constructs (list, array).

> 
> -Sara

---

## #65961 — Levi Morrison — 2013-02-19T16:09:08+00:00

URL: https://externals.io/message/65931#65961 · In reply to: #65937

There's already been an overwhelming negative reaction to this
particular proposed syntax so I won't belabor the point much.  In
short, this is too similar to block statements and does have BC
issues.

--

IF (and I stress if) we add a a shorter anonymous function syntax I'd
like it to be geared towards one-liners because that's where the
current syntax feels really verbose, especially when you close over
other variables:

    function ($n) use ($m) { return $m * $n; }

Versus one potential option:

    ($value) |$m| => $m * $n;

This syntax is short and expressive at the expense of clarity.
Basically all short-syntax has that trade-off, so I am personally fine
with it. The only other potential problem I see is parsing it; someone
more familiar with PHP's parser would have to verify whether that
would be a problem.

---

## #65962 — Levi Morrison — 2013-02-19T16:11:05+00:00

URL: https://externals.io/message/65931#65962 · In reply to: #65961

> IF (and I stress if) we add a a shorter anonymous function syntax I'd
> like it to be geared towards one-liners because that's where the
> current syntax feels really verbose, especially when you close over
> other variables:
>
>     function ($n) use ($m) { return $m * $n; }
>
> Versus one potential option:
>
>     ($value) |$m| => $m * $n;

My apologies, this was meant to read:

    ($n) |$m| => $m * $n;

---

Next page: https://externals.io/message/65931.md?page=2
