Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function trailing commas #241

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions language/functions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,31 @@ function takes_array($input)
]]>
</programlisting>
</example>
</para>
</para>
<para>
As of PHP 8.0.0, the list of function arguments may include a trailing comma, which
will be ignored. That is particularly useful in cases where the list of arguments is
long or contains long variable names, making it convenient to list arguments vertically.
</para>
<example>
<title>Passing arrays to functions</title>
<programlisting role="php">
<![CDATA[
<?php
function takes_many_args(
$first_arg,
$second_arg,
$a_very_long_argument_name,
$arg_with_default = 5,
$again = 'a default string', // This trailing comma was not permitted before 8.0.0.
)
{
// ...
}
?>
]]>
</programlisting>
</example>
<sect2 xml:id="functions.arguments.by-reference">
<title>Passing arguments by reference</title>

Expand Down Expand Up @@ -885,7 +909,7 @@ $greet('PHP');
<simpara>
Closures may also inherit variables from the parent scope. Any such
variables must be passed to the <literal>use</literal> language construct.
From PHP 7.1, these variables must not include &link.superglobals;,
As of PHP 7.1, these variables must not include &link.superglobals;,
<varname>$this</varname>, or variables with the same name as a parameter.
</simpara>

Expand Down Expand Up @@ -949,6 +973,10 @@ string(11) "hello world"
</screen>
</example>

<para>
As of PHP 8.0.0, the list of scope-inherited variables may include a trailing
comma, which will be ignored.
</para>
<simpara>
Inheriting variables from the parent scope is <emphasis>not</emphasis>
the same as using global variables.
Expand Down