svn: /phpdoc/ja/trunk/language/ functions.xml

From: Date: Sat, 05 Dec 2020 13:39:27 +0000
Subject: svn: /phpdoc/ja/trunk/language/ functions.xml
Groups: php.doc.ja 
Request: Send a blank email to doc-ja+get-5907@lists.php.net to get a copy of this message
mumumu Sat, 05 Dec 2020 13:39:27 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=351902 Log: Document named arguments Closes GH-251 Changed paths: U phpdoc/ja/trunk/language/functions.xml Modified: phpdoc/ja/trunk/language/functions.xml =================================================================== --- phpdoc/ja/trunk/language/functions.xml 2020-12-05 11:51:44 UTC (rev 351901) +++ phpdoc/ja/trunk/language/functions.xml 2020-12-05 13:39:27 UTC (rev 351902) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> <!-- $Revision$ --> -<!-- EN-Revision: 351885 Maintainer: takagi Status: working --> +<!-- EN-Revision: 351885 Maintainer: takagi Status: ready --> <!-- CREDITS: hirokawa,mumumu --> <chapter xml:id="language.functions" xmlns="http://docbook.org/ns/docbook"> <title>関数</title> @@ -231,23 +231,23 @@ </programlisting> </example> <para> - As of PHP 8.0.0, passing optional arguments after mandatory arguments - is deprecated. This can generally be resolved by dropping the default value. - One exception to this rule are arguments of the form - <code>Type $param = null</code>, where the &null; default makes the type implicitly - nullable. This usage remains allowed, though it is recommended to use an - explicit nullable type instead. + PHP 8.0.0 以降では、オプションの引数の後に、必須の引数を続けることは、 + 推奨されなくなります。 + 一般的には、デフォルト値を削除することで解決できます。 + このルールの唯一の例外は、<code>Type $param = null</code> と書かれた引数です。 + null をデフォルトにすることは、型が暗黙のうちに nullable であることを示しています。 + この書き方はまだ許可されていますが、明示的に nullable 型を使うことを推奨します。 </para> <example> - <title>Passing optional arguments after mandatory arguments</title> + <title>オプションの引数の後に、必須の引数を続ける</title> <programlisting role="php"> <![CDATA[ <?php -function foo($a = [], $b) {} // Before -function foo($a, $b) {} // After +function foo($a = [], $b) {} // PHP 8.0.0 より前 +function foo($a, $b) {} // PHP 8.0.0 以後 -function bar(A $a = null, $b) {} // Still allowed -function bar(?A $a, $b) {} // Recommended +function bar(A $a = null, $b) {} // PHP 8.0.0 でもまだ許可されています +function bar(?A $a, $b) {} // お勧めの書き方 ?> ]]> </programlisting> @@ -581,25 +581,23 @@ </sect2> <sect2 xml:id="functions.named-arguments"> - <title>Named Arguments</title> + <title>名前付き引数</title> <para> - PHP 8.0.0 introduced named arguments as an extension of the existing - positional parameters. Named arguments allow passing arguments to a - function based on the parameter name, rather than the parameter position. - This makes the meaning of the argument self-documenting, makes the - arguments order-independent and allows skipping default values arbitrarily. + 既にある、位置を指定した引数を拡張する形で、PHP 8.0.0 から名前付き引数が導入されました。 + 名前付き引数は、位置ではなく、名前ベースで引数を渡すことを可能にします。 + これによって、引数の意味が自己文書化(self-documenting)され、 + 引数を任意の順番で渡せるようになり、任意のデフォルト値を持つ引数をスキップできるようになります。 </para> <para> - Named arguments are passed by prefixing the value with the parameter name - followed by a colon. Using reserved keywords as parameter names is allowed. - The parameter name must be an identifier, specifying dynamically - is not allowed. + 名前付き引数は、引数の名前の後にコロンを付けたものを、値の前に付けることで指定します。 + 引数の名前にに予約語を使うことも許されています。 + 引数の名前は識別子でなければならず、動的に指定することは出来ません。 </para> <example> - <title>Named argument syntax</title> + <title>名前付き引数の文法</title> <programlisting role="php"> <![CDATA[ <?php @@ -606,7 +604,7 @@ myFunction(paramName: $value); array_foobar(array: $value); -// NOT supported. +// 以下の書き方はサポートされていません function_name($variableStoringParamName: $value); ?> ]]> @@ -614,14 +612,14 @@ </example> <example> - <title>Positional arguments versus named arguments</title> + <title>位置を指定した引数と、名前付き引数</title> <programlisting role="php"> <![CDATA[ <?php -// Using positional arguments: +// 位置を指定した引数の場合: array_fill(0, 100, 50); -// Using named arguments: +// 名前付き引数の場合: array_fill(start_index: 0, num: 100, value: 50); ?> ]]> @@ -629,11 +627,11 @@ </example> <para> - The order in which the named arguments are passed does not matter. + 名前付き引数は、渡す順番は関係ありません。 </para> <example> - <title>Same example as above with a different order of parameters</title> + <title>上と同じ例を、引数の順番を変えて渡す</title> <programlisting role="php"> <![CDATA[ <?php @@ -644,19 +642,19 @@ </example> <para> - Named arguments can be combined with positional arguments. In this case, - the named arguments must come after the positional arguments. - It is also possible to specify only some of the optional arguments of a - function, regardless of their order. + 名前付き引数は、位置を指定した引数と組み合わせることが出来ます。 + そうした場合、名前付き引数は、位置を指定した引数の後に置かなければいけません。 + オプションの引数だけをいくつか、指定することもできます。 + その場合も、名前付き引数の順番は関係ありません。 </para> <example> - <title>Combining named arguments with positional arguments</title> + <title>位置を指定した引数と、名前付き引数を組み合わせる</title> <programlisting role="php"> <![CDATA[ <?php htmlspecialchars($string, double_encode: false); -// Same as +// 上記は、以下と同等です。 htmlspecialchars($string, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); ?> ]]> @@ -664,11 +662,11 @@ </example> <para> - Passing the same parameter multiple times results in an Error exception. + 同じ引数を複数回渡すと、Error 例外が発生します。 </para> <example> - <title>Error exception when passing the same parameter multiple times</title> + <title>同じ引数を複数回渡すと、Error 例外が発生する</title> <programlisting role="php"> <![CDATA[ <?php

« previous php.doc.ja (#5907) next »