svn: /phpdoc/ja/trunk/language/types/ declarations.xml

[email protected] (Yoshinari Takaoka)
Newsgroups php.doc.ja
Message-ID <[email protected]>
mumumu                                   Fri, 13 Nov 2020 14:14:11 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=351380

Log:
[working] some translated union types.

Changed paths:
    U   phpdoc/ja/trunk/language/types/declarations.xml
svn-diffs-351380.txt (text/x-diff, 16 KB)
Modified: phpdoc/ja/trunk/language/types/declarations.xml
===================================================================
--- phpdoc/ja/trunk/language/types/declarations.xml	2020-11-13 12:16:31 UTC (rev 351379)
+++ phpdoc/ja/trunk/language/types/declarations.xml	2020-11-13 14:14:11 UTC (rev 351380)
@@ -6,8 +6,8 @@
  <title>型宣言</title>

  <para>
-  関数のパラメータや戻り値、PHP 7.4.0 以降では
-  クラスのプロパティに対して型を宣言することができます。
+  関数のパラメータや戻り値、
+  クラスのプロパティ (PHP 7.4.0 以降) に対して型を宣言することができます。
   これによって、その値が特定の型であることを保証できます。
   その型でない場合は、<classname>TypeError</classname> がスローされます。
  </para>
@@ -275,7 +275,7 @@
  </sect2>

  <sect2 xml:id="language.types.declarations.nullable">
-  <title>Nullを許容する型宣言</title>
+  <title>Null を許容する型宣言</title>

   <para>
    PHP 7.1.0 以降では、型の名前の前にクエスチョンマーク
@@ -285,7 +285,7 @@

   <para>
    <example>
-    <title>Nullを許容する型宣言</title>
+    <title>Null を許容する型宣言</title>
     <programlisting role="php">
 <![CDATA[
 <?php
@@ -363,85 +363,85 @@
   </note>
  </sect2>

- <!-- to be translated -->
  <sect2 xml:id="language.types.declarations.union">
-  <title>Union types</title>
+  <title>union 型</title>
   <para>
-   A union type declaration accepts values of multiple different types,
-   rather than a single one.
-   Union types are specified using the syntax <literal>T1|T2|...</literal>.
-   Union types are available as of PHP 8.0.0.
+   型を union として宣言すると、ひとつではなく、
+   複数の異なる型を値として受け入れることができます。
+   union 型は、<literal>T1|T2|...</literal> という文法を使って指定します。
+   union 型は、PHP 8.0.0 以降で利用可能です。
   </para>

   <sect3 xml:id="language.types.declarations.union.nullable">
-   <title>Nullable union types</title>
+   <title>Nullを受け入れる union 型</title>
    <para>
-    The <literal>null</literal> type is supported as part of unions,
-    such that <literal>T1|T2|null</literal> can be used to create a nullable union.
-    The existing <literal>?T</literal> notation is considered a shorthand
-    for the common case of <literal>T|null</literal>.
+    <literal>null</literal> 型も union 型の一部としてサポートされています。
+    null を受け入れる union を作るために、
+    <literal>T1|T2|null</literal> のような指定をすることができます。
+    既にある <literal>?T</literal> 記法は、
+    よくある <literal>T|null</literal> の短縮記法と考えられます。
    </para>

    <caution>
     <simpara>
-     <literal>null</literal> cannot be used as a standalone type.
+     <literal>null</literal> は、単独の、独立した型として使うことは出来ません。
     </simpara>
    </caution>
   </sect3>

   <sect3 xml:id="language.types.declarations.union.false">
-   <title>false pseudo-type</title>
+   <title>false 疑似型</title>
    <para>
-    The <literal>false</literal> literal type is supported as part of unions,
-    and is included as for historical reasons many internal functions return
-    <literal>false</literal> instead of <literal>null</literal> for failures.
-    A classic example of such a function is <function>strpos</function>.
+    <literal>false</literal> リテラルの型が、union の一部としてサポートされています。
+    歴史的な理由で、多くの内部関数が失敗時に <literal>null</literal>
+    ではなく <literal>false</literal>  を返しているためです。
+    <function>strpos</function> 関数は、このような関数の典型例です。
    </para>

    <caution>
     <simpara>
-     <literal>false</literal> cannot be used as a standalone type (including
-     nullable standalone type).
-     As such, all of <literal>false</literal>, <literal>false|null</literal>
-     and <literal>?false</literal> are not permitted.
+     <literal>false</literal> 疑似型は、単独の、独立した型
+     (単独な null を許容する型としても)
+     として使うことは出来ません。
+     したがって、<literal>false</literal>, <literal>false|null</literal>,
+     <literal>?false</literal> はいずれも許されません。
     </simpara>
    </caution>
+
    <caution>
     <simpara>
-     The <literal>true</literal> literal type does <emphasis>not</emphasis>
-     exist.
+     <literal>true</literal> リテラルの型は存在 <emphasis>しません</emphasis>
     </simpara>
    </caution>
   </sect3>

   <sect3 xml:id="language.types.declarations.union.redundant">
-   <title>Duplicate and redundant types</title>
+   <title>重複した冗長な型</title>
    <para>
-    To catch simple bugs in union type declarations, redundant types that
-    can be detected without performing class loading will result in a
-    compile-time error. This includes:
-
+    union 型の宣言に関する単純なバグを見つけるため、
+    クラスを読み込みを行わずに検出できる冗長な型はコンパイル時にエラーになります。
+    たとえば、以下のような場合です:
     <itemizedlist>
      <listitem>
       <simpara>
-       Each name-resolved type may only occur once. Types such as
-       <literal>int|string|INT</literal> result in an error.
+       名前が解決された型は、一度しか現れることができません。
+       <literal>int|string|INT</literal> のような型はエラーになります。
       </simpara>
      </listitem>
      <listitem>
       <simpara>
-       If <type>bool</type> is used, <type>false</type> cannot be used additionally.
+       <type>bool</type> 型が使われている場合、<type>false</type> 疑似型は追加で使えません。
       </simpara>
      </listitem>
      <listitem>
       <simpara>
-       If <type>object</type> is used, class types cannot be used additionally.
+       <type>object</type> 型が使われている場合、クラスの型は追加で使えません。
       </simpara>
      </listitem>
      <listitem>
       <simpara>
-       If <type>iterable</type> is used, <type>array</type>
-       and <classname>Traversable</classname> cannot be used additionally.
+       <type>iterable</type> 型が使われている場合、 <type>array</type>
+       と <classname>Traversable</classname> は追加で使えません。
       </simpara>
      </listitem>
     </itemizedlist>
@@ -449,32 +449,34 @@

    <note>
     <simpara>
-     This does not guarantee that the type is “minimal”, because doing so would
-     require loading all used class types.
+     これによって、型が "最低限" であることは保証しません。
+     なぜなら、最低限であることを保証するためには、
+     使われている全てのクラスの型を読み込まなければならないからです。
     </simpara>
    </note>

    <para>
-    For example, if <literal>A</literal> and <literal>B</literal> are class
-    aliases, then <literal>A|B</literal> remains a legal union type, even
-    though it could be reduced to either <literal>A</literal> or
-    <literal>B</literal>.
-    Similarly, if class <code>B extends A {}</code>, then <literal>A|B</literal>
-    is also a legal union type, even though it could be reduced to just
-    <literal>A</literal>.
-
+    たとえば、<literal>A</literal> と <literal>B</literal>
+    がクラスのエイリアスだったとします。
+    この場合、<literal>A|B</literal> は
+    <literal>A</literal> または <literal>B</literal> のみに縮めることができますが、
+    正しい union 型です。
+    同様に、<code>B extends A {}</code> というクラスがあった場合、
+    <literal>A|B</literal> は
+    <literal>A</literal> のみに縮めることができますが、
+    正しい union 型です。
     <informalexample>
      <programlisting role="php">
 <![CDATA[
 <?php
-function foo(): int|INT {} // Disallowed
-function foo(): bool|false {} // Disallowed
+function foo(): int|INT {} // 許されません
+function foo(): bool|false {} // 許されません

 use A as B;
-function foo(): A|B {} // Disallowed ("use" is part of name resolution)
+function foo(): A|B {} // 許されません ("use" は名前解決の一部です)

 class_alias('X', 'Y');
-function foo(): X|Y {} // Allowed (redundancy is only known at runtime)
+function foo(): X|Y {} // 問題ありません (冗長かどうかは、実行時にだけわかります)
 ?>
 ]]>
      </programlisting>
@@ -485,15 +487,14 @@
  </sect2>

  <sect2 xml:id="language.types.declarations.return-only">
-  <title>Return only types</title>
+  <title>返り値でのみ有効な型</title>

   <sect3 xml:id="language.types.declarations.void">
    <title>void</title>
    <para>
-    <literal>void</literal> is a return type indicating the function does not
-    return a value.
-    Therefore it cannot be part of a union type declaration.
-    Available as of PHP 7.1.0.
+    <literal>void</literal> は、関数が値を返さないことを示す戻り値の型です。
+    よって、この型は union 型の一部として指定することが出来ません。
+    PHP 7.1.0 以降で利用できます。
    </para>
   </sect3>

@@ -500,62 +501,62 @@
   <sect3 xml:id="language.types.declarations.static">
    <title>static</title>
    <para>
-    The value must be an &instanceof; the same class as the one the
-    method is called in.
-    Available as of PHP 8.0.0.
+    値が、メソッドが呼び出されているクラスと同じインスタンスでなければなりません。
+    PHP 8.0.0 以降で利用できます。
    </para>
   </sect3>
  </sect2>

  <sect2 xml:id="language.types.declarations.strict">
-  <title>Strict typing</title>
+  <title>厳密な型付け</title>

   <para>
-   By default, PHP will coerce values of the wrong type into the expected
-   scalar type declaration if possible. For example, a function that is given
-   an <type>int</type> for a parameter that expects a <type>string</type>
-   will get a variable of type <type>string</type>.
+   デフォルトでは、PHP は誤った型の値を
+   可能であれば期待されたスカラー型の宣言に従うように強制します。
+   たとえば、関数に <type>int</type> が与えられたが、
+   引数に文字列が期待されていた場合、
+   文字列型の値を取得します。
   </para>

   <para>
-   It is possible to enable strict mode on a per-file basis. In strict
-   mode, only a value corresponding exactly to the type declaration will be
-   accepted, otherwise a <classname>TypeError</classname> will be thrown.
-   The only exception to this rule is that an <type>int</type> value will
-   pass a <type>float</type> type declaration.
+   ファイルごとに strict モードを有効にすることができます。
+   strict モードでは、型宣言に正確に対応する値のみを受け入れ、
+   そうでない場合、<classname>TypeError</classname> がスローされます。
+   このルールに関する唯一の例外は、<type>int</type> の値が
+   <type>float</type> 型の宣言に渡せることだけです。
   </para>

   <warning>
    <simpara>
-    Function calls from within internal functions will not be affected by
-    the <literal>strict_types</literal> declaration.
+    内部関数の中からの関数呼び出しは、
+    <literal>strict_types</literal> 宣言の影響を受けません。
    </simpara>
   </warning>

   <para>
-   To enable strict mode, the &declare; statement is used with the
-   <literal>strict_types</literal> declaration:
+   strict モードを有効にするには、&declare; 文を
+   <literal>strict_types</literal> 宣言と一緒に使います。
   </para>

   <note>
    <para>
-    Strict typing applies to function calls made from
-    <emphasis>within</emphasis> the file with strict typing enabled, not to
-    the functions declared within that file. If a file without strict
-    typing enabled makes a call to a function that was defined in a file
-    with strict typing, the caller's preference (coercive typing) will be
-    respected, and the value will be coerced.
+    厳密な型付けは、strict モードが有効になったファイルの
+    <emphasis>内部</emphasis> から行われる関数呼び出しに適用されます。
+    そのファイルで宣言された関数に対する呼び出しについては適用されません。
+    厳密な型付けが有効になっていないファイルから、
+    厳密な型付けが有効になっているファイルで定義された関数を呼び出した場合は、
+    呼び出し側の好み(型の強制)が尊重され、値は型変換されます。
    </para>
   </note>

   <note>
    <para>
-    Strict typing is only defined for scalar type declarations.
+    厳密な型付けは、スカラー型の宣言に対してのみ定義されます。
    </para>
   </note>

   <example>
-   <title>Strict typing for arguments values</title>
+   <title>引数の値に対する厳密な型付け</title>
    <programlisting role="php">
 <![CDATA[
 <?php
@@ -585,7 +586,7 @@
   </example>

   <example>
-   <title>Coercive typing for argument values</title>
+   <title>引数の値に対する型の強制</title>
    <programlisting role="php">
 <![CDATA[
 <?php
@@ -595,7 +596,7 @@

 var_dump(sum(1, 2));

-// These will be coerced to integers: note the output below!
+// これらは、整数型に強制されます: 以下の出力を参照!
 var_dump(sum(1.5, 2.5));
 ?>
 ]]>
@@ -610,7 +611,7 @@
   </example>

   <example>
-   <title>Strict typing for return values</title>
+   <title>戻り値に対する厳密な型付け</title>
    <programlisting role="php">
 <![CDATA[
 <?php
@@ -641,12 +642,13 @@
  </sect2>

  <sect2 xml:id="language.types.declarations.union.coercive">
-  <title>Coercive typing with union types</title>
+  <title>union 型と型の強制</title>
+
   <para>
-   When <literal>strict_types</literal> is not enabled, scalar type declarations
-   are subject to limited implicit type coercions.
-   If the exact type of the value is not part of the union, then the target type
-   is chosen in the following order of preference:
+   <literal>strict_types</literal> が有効になっていない場合、
+   スカラー型の宣言は、限られた暗黙の型強制に従います。
+   値の正確な型が union の一部に指定されていない場合、
+   次の順に対象になる型が選択されます:

    <orderedlist>
     <listitem>
@@ -671,6 +673,7 @@
     </listitem>
    </orderedlist>

+   <!-- to be translated -->
    If the type both exists in the union, and the value can be coerced to the
    type under PHPs existing type checking semantics, then the type is chosen.
    Otherwise the next type is tried.
@@ -727,13 +730,13 @@

 <!-- TODO figure out what do to with these things -->
  <sect2 xml:id="language.types.declarations.misc">
-  <title>Misc</title>
+  <title>その他</title>
    <example>
-    <title>Typed pass-by-reference Parameters</title>
+    <title>参照渡しの引数に対する型宣言</title>
     <simpara>
-     Declared types of reference parameters are checked on function entry, but
-     not when the function returns, so after the function had returned, the
-     argument's type may have changed.
+     参照渡しの引数に対して宣言される方は、関数の入り口でチェックされますが、
+     関数から返される時はチェックされません。よって、関数から戻った後は、
+     引数の型が変わっているかもしれません。
     </simpara>
     <programlisting role="php">
 <![CDATA[
@@ -764,7 +767,7 @@
    </example>

    <example>
-    <title>Catching <classname>TypeError</classname></title>
+    <title><classname>TypeError</classname> をキャッチする</title>
     <programlisting role="php">
 <![CDATA[
 <?php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.