diff --git a/appendices/migration81/incompatible.xml b/appendices/migration81/incompatible.xml index 98e72cb5bc..8f2fc55824 100644 --- a/appendices/migration81/incompatible.xml +++ b/appendices/migration81/incompatible.xml @@ -63,8 +63,10 @@ var_dump(B::counter()); // int(4), previously int(2) specified before required parameters is now always treated as required, even when called using named arguments. - In PHP 8.0, the below emits a deprecation notice on the definition, - but runs successfully when called. As of PHP 8.1, an error is thrown. + As of PHP 8.0.0, but prior to PHP 8.1.0, the below emits a deprecation notice + on the definition, but runs successfully when called. As of PHP 8.1.0, an error + of class ArgumentCountError is thrown, as it would be when + called with positional arguments. @@ -87,7 +89,7 @@ catch (Error $e) &example.outputs.80; - - + + + Note that a default value of &null; can be used before required parameters to + specify a nullable type, + but the parameter will still be required. diff --git a/language/functions.xml b/language/functions.xml index accf2bed42..acaadf518f 100644 --- a/language/functions.xml +++ b/language/functions.xml @@ -224,28 +224,6 @@ function takes_many_args( // ... } ?> -]]> - - - - As of PHP 8.0.0, declaring mandatory arguments after optional arguments - is deprecated. This can generally be resolved by dropping the default value. - One exception to this rule are arguments of the form - Type $param = null, where the &null; default makes the type implicitly - nullable. This usage remains allowed, though it is recommended to use an - explicit nullable type instead. - - - Declaring optional arguments after mandatory arguments - - ]]> @@ -291,7 +269,8 @@ echo $str; // outputs 'This is a string, and something extra.' A function may define default values for arguments using syntax similar to assigning a variable. The default is used only when the parameter is - not specified. + not specified; in particular, note that passing &null; does not + assign the default value. @@ -321,7 +300,7 @@ Making a cup of espresso. Default parameter values may be scalar values, arrays, - the special type &null;, and as of PHP 8.1, objects using the + the special type &null;, and as of PHP 8.1.0, objects using the new ClassName() syntax. @@ -343,7 +322,7 @@ echo makecoffee(array("cappuccino", "lavazza"), "teapot");?> - Using objects as default values (as of PHP 8.1) + Using objects as default values (as of PHP 8.1.0) - As of PHP 8.0, named arguments + As of PHP 8.0.0, named arguments can be used to skip over multiple optional parameters. @@ -454,17 +433,35 @@ Making a bowl of raspberry natural yogurt. + + As of PHP 8.0.0, declaring mandatory arguments after optional arguments + is deprecated. This can generally be resolved by + dropping the default value, since it will never be used. + One exception to this rule are arguments of the form + Type $param = null, where the &null; default makes the type implicitly + nullable. This usage remains allowed, though it is recommended to use an + explicit nullable type instead. + + Declaring optional arguments after mandatory arguments + + + ]]> + + + - As of PHP 7.1, omitting a parameter which does not specify a default + As of PHP 7.1.0, omitting a parameter which does not specify a default throws an ArgumentCountError; in previous versions it raised a Warning. - - As of PHP 8.0, defining a function with optional - parameters after required parameters (as in the first "yogurt" - example above) is DEPRECATED. - @@ -671,7 +668,7 @@ echo sum(1, 2, 3, 4); Named argument syntax - Positional arguments versus named arguments - Same example as above with a different order of parameters - @@ -723,7 +720,7 @@ array_fill(value: 50, count: 100, start_index: 0); Combining named arguments with positional arguments - - Error exception when passing the same parameter multiple times + Error thrown when passing the same parameter multiple times -