55
66 <sect1 xml : id =" functions.user-defined" >
77 <title >User-defined functions</title >
8-
8+
99 <para >
1010 A function may be defined using syntax such as the following:
1111 </para >
@@ -168,14 +168,16 @@ function recursion($a)
168168 </para >
169169
170170 </sect1 >
171-
171+
172172 <sect1 xml : id =" functions.arguments" >
173- <title >Function arguments</title >
174-
173+ <title >Function parameters and arguments</title >
174+
175175 <simpara >
176+ The function parameters are declared in the function signature.
176177 Information may be passed to functions via the argument list,
177178 which is a comma-delimited list of expressions. The arguments are
178- evaluated from left to right, before the function is actually called
179+ evaluated from left to right and the result is assigned to the parameters of
180+ the function, before the function is actually called
179181 (<emphasis >eager</emphasis > evaluation).
180182 </simpara >
181183
@@ -204,12 +206,12 @@ function takes_array($input)
204206 </example >
205207 </para >
206208 <para >
207- As of PHP 8.0.0, the list of function arguments may include a trailing comma, which
208- will be ignored. That is particularly useful in cases where the list of arguments is
209- long or contains long variable names, making it convenient to list arguments vertically.
209+ As of PHP 8.0.0, the list of function parameters may include a trailing comma, which
210+ will be ignored. That is particularly useful in cases where the list of parameters is
211+ long or contains long variable names, making it convenient to list parameters vertically.
210212 </para >
211213 <example >
212- <title >Function Argument List with trailing Comma </title >
214+ <title >Function parameter list with trailing comma </title >
213215 <programlisting role =" php" >
214216<![CDATA[
215217<?php
@@ -230,7 +232,7 @@ function takes_many_args(
230232
231233 <sect2 xml : id =" functions.arguments.by-reference" >
232234 <title >Passing arguments by reference</title >
233-
235+
234236 <simpara >
235237 By default, function arguments are passed by value (so that if
236238 the value of the argument within the function is changed, it does
@@ -239,11 +241,11 @@ function takes_many_args(
239241 </simpara >
240242 <para >
241243 To have an argument to a function always passed by reference, prepend an
242- ampersand (& ) to the argument name in the function definition:
244+ ampersand (& ) to the parameter name in the function definition:
243245 </para >
244246 <para >
245247 <example >
246- <title >Passing function parameters by reference</title >
248+ <title >Passing function arguments by reference</title >
247249 <programlisting role =" php" >
248250<![CDATA[
249251<?php
@@ -260,16 +262,16 @@ echo $str; // outputs 'This is a string, and something extra.'
260262 </example >
261263 </para >
262264 <para >
263- It is an error to pass a value as argument which is supposed to be passed by reference.
265+ It is an error to pass a constant expression as argument to parameter that expects to be passed by reference.
264266 </para >
265267 </sect2 >
266268 <sect2 xml : id =" functions.arguments.default" >
267- <title >Default argument values</title >
268-
269+ <title >Default parameter values</title >
270+
269271 <para >
270- A function may define default values for arguments using syntax similar
271- to assigning a variable. The default is used only when the parameter is
272- not specified; in particular, note that passing &null; does <emphasis >not</emphasis >
272+ A function may define default values for parameters using syntax similar
273+ to assigning a variable. The default is used only when the parameter's argument is
274+ not passed. Note that passing &null; does <emphasis >not</emphasis >
273275 assign the default value.
274276 </para >
275277 <para >
@@ -367,21 +369,21 @@ Crafting a beautiful coffee just for you.
367369 example) a variable, a class member or a function call.
368370 </simpara >
369371 <para >
370- Note that any optional arguments should be specified after any
371- required arguments , otherwise they cannot be omitted from calls.
372+ Note that any optional parameters should be specified after any
373+ required parameters , otherwise they cannot be omitted from calls.
372374 Consider the following example:
373375 </para >
374376 <para >
375377 <example >
376- <title >Incorrect usage of default function arguments </title >
378+ <title >Incorrect usage of default function parameters </title >
377379 <programlisting role =" php" >
378380<![CDATA[
379381<?php
380382function makeyogurt($container = "bowl", $flavour)
381383{
382384 return "Making a $container of $flavour yogurt.\n";
383385}
384-
386+
385387echo makeyogurt("raspberry"); // "raspberry" is $container, not $flavour
386388?>
387389]]>
@@ -400,15 +402,15 @@ Fatal error: Uncaught ArgumentCountError: Too few arguments
400402 </para >
401403 <para >
402404 <example >
403- <title >Correct usage of default function arguments </title >
405+ <title >Correct usage of default function parameters </title >
404406 <programlisting role =" php" >
405407<![CDATA[
406408<?php
407409function makeyogurt($flavour, $container = "bowl")
408410{
409411 return "Making a $container of $flavour yogurt.\n";
410412}
411-
413+
412414echo makeyogurt("raspberry"); // "raspberry" is $flavour
413415?>
414416]]>
@@ -427,7 +429,7 @@ Making a bowl of raspberry yogurt.
427429 </para >
428430 <para >
429431 <example >
430- <title >Correct usage of default function arguments </title >
432+ <title >Correct usage of default function parameters </title >
431433 <programlisting role =" php" >
432434<![CDATA[
433435<?php
@@ -449,16 +451,16 @@ Making a bowl of raspberry natural yogurt.
449451 </example >
450452 </para >
451453 <para >
452- As of PHP 8.0.0, declaring mandatory arguments after optional arguments
454+ As of PHP 8.0.0, declaring mandatory parameters after optional parameters
453455 is <emphasis >deprecated</emphasis >. This can generally be resolved by
454456 dropping the default value, since it will never be used.
455- One exception to this rule are arguments of the form
457+ One exception to this rule are parameters of the form
456458 <code >Type $param = null</code >, where the &null; default makes the type implicitly
457459 nullable. This usage is deprecated as of PHP 8.4.0, and an explicit
458460 <link linkend =" language.types.declarations.nullable" >nullable type</link >
459461 should be used instead.
460462 <example >
461- <title >Declaring optional arguments after mandatory arguments </title >
463+ <title >Declaring optional parameters after mandatory parameters </title >
462464 <programlisting role =" php" >
463465<![CDATA[
464466<?php
@@ -486,7 +488,7 @@ function bar(?A $a, $b) {} // Recommended
486488 </note >
487489 <note >
488490 <simpara >
489- Arguments that are passed by reference may have a default value.
491+ Parameters that expect the argument by reference may have a default value.
490492 </simpara >
491493 </note >
492494 </sect2 >
@@ -501,7 +503,7 @@ function bar(?A $a, $b) {} // Recommended
501503 </simpara >
502504
503505 <para >
504- Argument lists may include the
506+ Parameter lists may include the
505507 <literal >...</literal > token to denote that the function accepts a
506508 variable number of arguments. The arguments will be passed into the
507509 given variable as an &array; :
@@ -564,7 +566,7 @@ echo add(...$a);
564566 </para >
565567
566568 <para >
567- You may specify normal positional arguments before the
569+ You may specify normal positional parameters before the
568570 <literal >...</literal > token. In this case, only the trailing arguments
569571 that don't match a positional argument will be added to the array
570572 generated by <literal >...</literal >.
@@ -701,20 +703,24 @@ htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8', fa
701703 </example >
702704
703705 <para >
704- Passing the same parameter multiple times results in an Error exception.
706+ Passing an argument to the same named parameter multiple times results in an
707+ <classname >Error</classname > exception.
705708 </para >
706709
707710 <example >
708- <title >Error thrown when passing the same parameter multiple times</title >
711+ <title >Error thrown when passing an argument to the same named parameter multiple times</title >
709712 <programlisting role =" php" >
710713<![CDATA[
711714<?php
715+
712716function foo($param) { ... }
713717
714718foo(param: 1, param: 2);
715719// Error: Named parameter $param overwrites previous argument
720+
716721foo(1, param: 2);
717722// Error: Named parameter $param overwrites previous argument
723+
718724?>
719725]]>
720726 </programlisting >
@@ -745,10 +751,10 @@ var_dump(foo(...[1, 2], b: 20)); // Fatal error. Named parameter $b overwrites p
745751
746752 </sect2 >
747753 </sect1 >
748-
754+
749755 <sect1 xml : id =" functions.returning-values" >
750756 <title >Returning values</title >
751-
757+
752758 <para >
753759 Values are returned by using the optional return statement. Any
754760 type may be returned, including arrays and objects. This causes the
@@ -1463,7 +1469,7 @@ Warning: Cannot bind an instance to a static closure in %s on line %d
14631469<?php
14641470
14651471$y = 1;
1466-
1472+
14671473$fn1 = fn($x) => $x + $y;
14681474// equivalent to using $y by value:
14691475$fn2 = function ($x) use ($y) {
@@ -1712,7 +1718,7 @@ $obj?->prop->method(...);
17121718 </sect1 >
17131719
17141720 </chapter >
1715-
1721+
17161722<!-- Keep this comment at the end of the file
17171723Local variables:
17181724mode: sgml
0 commit comments