Fix 71082: Order of use clause and return type declaration unspecified

This commit is contained in:
Christoph M. Becker 2021-09-13 17:20:48 +02:00
parent f739452fff
commit 871fdba56f
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6

View file

@ -1049,6 +1049,8 @@ $greet('PHP');
variables must be passed to the <literal>use</literal> language construct.
As of PHP 7.1, these variables must not include &link.superglobals;,
<varname>$this</varname>, or variables with the same name as a parameter.
A return type declaration of the function has to be placed
<emphasis>after</emphasis> the <literal>use</literal> clause.
</simpara>
<example>
@ -1094,6 +1096,12 @@ $example = function ($arg) use ($message) {
var_dump($arg . ' ' . $message);
};
$example("hello");
// Return type declaration comes after the use clause
$example = function () use ($message): string {
return "hello $message";
};
var_dump($example());
?>
]]>
</programlisting>
@ -1107,6 +1115,7 @@ string(5) "hello"
string(5) "hello"
string(5) "world"
string(11) "hello world"
string(11) "hello world"
]]>
</screen>
</example>