svn: /phpdoc/ja/trunk/ appendices/migration70/new-features.xml language/control-structures/declare.xml language/control-structures/return.xml language/functions.xml language/oop5/interfaces.xml language/oop5/typehinting.xml language/oop5.xml language/types/declarations.xml language/types.xml language-snippets.ent reference/filesystem/functions/file-get-contents.xml
[email protected] (Yoshinari Takaoka)
| Newsgroups | php.doc.ja |
|---|---|
| Message-ID | <[email protected]> |
mumumu Fri, 13 Nov 2020 00:31:04 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=351371
Log:
Split type declarations into their dedicated page
Changed paths:
U phpdoc/ja/trunk/appendices/migration70/new-features.xml
U phpdoc/ja/trunk/language/control-structures/declare.xml
U phpdoc/ja/trunk/language/control-structures/return.xml
U phpdoc/ja/trunk/language/functions.xml
U phpdoc/ja/trunk/language/oop5/interfaces.xml
D phpdoc/ja/trunk/language/oop5/typehinting.xml
U phpdoc/ja/trunk/language/oop5.xml
A phpdoc/ja/trunk/language/types/declarations.xml
U phpdoc/ja/trunk/language/types.xml
U phpdoc/ja/trunk/language-snippets.ent
U phpdoc/ja/trunk/reference/filesystem/functions/file-get-contents.xml
svn-diffs-351371.txt
(text/x-diff, 53.5 KB)
Modified: phpdoc/ja/trunk/appendices/migration70/new-features.xml
===================================================================
--- phpdoc/ja/trunk/appendices/migration70/new-features.xml 2020-11-12 23:53:01 UTC (rev 351370)
+++ phpdoc/ja/trunk/appendices/migration70/new-features.xml 2020-11-13 00:31:04 UTC (rev 351371)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 351133 Maintainer: takagi Status: ready -->
+<!-- EN-Revision: 351365 Maintainer: takagi Status: ready -->
+<!-- Credits: mumumu -->
<sect1 xml:id="migration70.new-features" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>新機能</title>
@@ -10,7 +11,7 @@
<para>
スカラー
- <link linkend="functions.arguments.type-declaration">型宣言</link>
+ <link linkend="language.types.declarations">型宣言</link>
には二つの方式があります。デフォルトの自動変換 (coercive) モードと、
厳密に判断する strict モードです。
パラメータとして、
@@ -46,13 +47,13 @@
strict モードを有効にするには、ファイルの先頭に &declare; ディレクティブを置く必要があります。
つまり、スカラー型を厳密に扱うかどうかは、ファイル単位で定めるということです。
このディレクティブは、パラメータの型宣言だけでなく、関数の戻り値の型
- (<link linkend="functions.returning-values.type-declaration">戻り値の型宣言</link>を参照ください)
+ (<link linkend="language.types.declarations">戻り値の型宣言</link>を参照ください)
や PHP の標準関数、そして拡張モジュールの関数にも影響を及ぼします。
</para>
<para>
スカラー型宣言に関するドキュメントやサンプルについては、
- <link linkend="functions.arguments.type-declaration">型宣言</link>
+ <link linkend="language.types.declarations">型宣言</link>
を参照ください。
</para>
</sect2>
@@ -62,12 +63,12 @@
<para>
PHP 7 では、
- <link linkend="functions.returning-values.type-declaration">戻り値の型宣言</link>
+ <link linkend="language.types.declarations">戻り値の型宣言</link>
もできるようになりました。
- <link linkend="functions.arguments.type-declaration">引数の型宣言</link>
+ <link linkend="language.types.declarations">引数の型宣言</link>
と同様に、戻り値の型宣言では、関数が戻す値がどの型になるかを宣言します。
戻り値の型宣言で使える
- <link linkend="functions.arguments.type-declaration.types">型</link>
+ <link linkend="language.types.declarations">型</link>
は、引数の型宣言で使えるものと同じです。
</para>
@@ -101,7 +102,7 @@
<para>
詳細なドキュメントやサンプルについては、
- <link linkend="functions.returning-values.type-declaration">戻り値の型宣言</link>.
+ <link linkend="language.types.declarations">戻り値の型宣言</link>.
を参照ください。
</para>
</sect2>
Modified: phpdoc/ja/trunk/language/control-structures/declare.xml
===================================================================
--- phpdoc/ja/trunk/language/control-structures/declare.xml 2020-11-12 23:53:01 UTC (rev 351370)
+++ phpdoc/ja/trunk/language/control-structures/declare.xml 2020-11-13 00:31:04 UTC (rev 351371)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 351112 Maintainer: takagi Status: ready -->
+<!-- EN-Revision: 351365 Maintainer: takagi Status: ready -->
<!-- Credits: mumumu -->
<sect1 xml:id="control-structures.declare" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
@@ -30,7 +30,7 @@
(<link linkend="control-structures.declare.encoding">encoding</link>
に関しては以下を参照ください)、
<literal>strict_types</literal>
- (<link linkend="functions.arguments.type-declaration.strict">strict</link>
+ (<link linkend="language.types.declarations.strict">strict</link>
に関しては関数の引数のページを参照ください) です。
</para>
Modified: phpdoc/ja/trunk/language/control-structures/return.xml
===================================================================
--- phpdoc/ja/trunk/language/control-structures/return.xml 2020-11-12 23:53:01 UTC (rev 351370)
+++ phpdoc/ja/trunk/language/control-structures/return.xml 2020-11-13 00:31:04 UTC (rev 351371)
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 344782 Maintainer: takagi Status: ready -->
+<!-- EN-Revision: 351365 Maintainer: takagi Status: ready -->
+<!-- Credits: mumumu -->
<sect1 xml:id="function.return" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>return</title>
@@ -51,6 +52,14 @@
</simpara>
</note>
</para>
+
+ <para>
+ PHP 7.1.0 以降では、戻り値の型が
+ <type>void</type> でない場合、引数なしの <literal>return</literal> 文は
+ <constant>E_COMPILE_ERROR</constant> が発生するようになりました。
+ 戻り値の型が <type>void</type> の場合、
+ <literal>return</literal> 文に引数があると、同様のエラーが発生します。
+ </para>
</sect1>
<!-- Keep this comment at the end of the file
Modified: phpdoc/ja/trunk/language/functions.xml
===================================================================
--- phpdoc/ja/trunk/language/functions.xml 2020-11-12 23:53:01 UTC (rev 351370)
+++ phpdoc/ja/trunk/language/functions.xml 2020-11-13 00:31:04 UTC (rev 351371)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 351340 Maintainer: takagi Status: ready -->
+<!-- EN-Revision: 351365 Maintainer: takagi Status: ready -->
<!-- CREDITS: hirokawa,mumumu -->
<chapter xml:id="language.functions" xmlns="http://docbook.org/ns/docbook">
<title>関数</title>
@@ -364,412 +364,6 @@
</note>
</sect2>
- <sect2 xml:id="functions.arguments.type-declaration">
- <title>型宣言</title>
-
- <note>
- <para>
- 型宣言は、以前のバージョンのPHPではタイプヒンティングとも呼ばれていました。
- </para>
- </note>
-
- <para>
- 型宣言を使うと、関数を呼ぶ際に渡すパラメータが特定の型であることを、関数の宣言時に要求できるようになります。
- 関数に渡された値が不正な型であった場合はエラーとなります。
- この場合、<classname>TypeError</classname> 例外がスローされます。
- </para>
-
- <para>
- 型宣言を指定するには、型の名前をパラメータ名の前に追加します。
- パラメータのデフォルト値が &null; である場合は、型宣言でも &null;
- 値を受け付けることができます。
- </para>
-
- <sect3 xml:id="functions.arguments.type-declaration.types">
- <title>有効な型</title>
- <informaltable>
- <tgroup cols="3">
- <thead>
- <row>
- <entry>型</entry>
- <entry>説明</entry>
- <entry>利用可能な PHP の最低バージョン</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>クラス名 / インターフェイス名</entry>
- <entry>
- パラメータは、指定したクラスやインターフェイスのインスタンスでなければいけません。
- </entry>
- <entry></entry>
- </row>
- <row>
- <entry><literal>self</literal></entry>
- <entry>
- パラメータは、そのメソッドが定義されているクラスと同じクラスのインスタンスでなければいけません。
- これが使えるのは、クラスメソッドやインスタンスメソッドだけです。
- </entry>
- <entry></entry>
- </row>
- <row>
- <entry><type>array</type></entry>
- <entry>
- パラメータは配列でなければいけません。
- </entry>
- <entry></entry>
- </row>
- <row>
- <entry><type>callable</type></entry>
- <entry>
- パラメータは <type>callable</type> でなければいけません。
- </entry>
- <entry></entry>
- </row>
- <row>
- <entry><type>bool</type></entry>
- <entry>
- パラメータは <type>bool</type> 値でなければいけません。
- </entry>
- <entry></entry>
- </row>
- <row>
- <entry><type>float</type></entry>
- <entry>
- パラメータは <type>float</type> でなければいけません。
- </entry>
- <entry></entry>
- </row>
- <row>
- <entry><type>int</type></entry>
- <entry>
- パラメータは <type>int</type> でなければいけません。
- </entry>
- <entry></entry>
- </row>
- <row>
- <entry><type>string</type></entry>
- <entry>
- パラメータは <type>string</type> でなければいけません。
- </entry>
- <entry></entry>
- </row>
- <row>
- <entry><literal>iterable</literal></entry>
- <entry>
- パラメータは、<type>array</type>
- または <classname>Traversable</classname> &instanceof; でなければいけません。
- </entry>
- <entry>PHP 7.1.0</entry>
- </row>
- <row>
- <entry><literal>object</literal></entry>
- <entry>
- パラメータは、<type>object</type> でなければいけません。
- </entry>
- <entry>PHP 7.2.0</entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
-
- <warning>
- <para>
- これらのスカラー型のエイリアスはサポートしていません。
- エイリアスは、クラス名あるいはインターフェイス名として解釈されます。
- つまり、パラメータや返り値の型として
- <literal>boolean</literal> を用いると、
- <type>bool</type> であることを宣言したのではなく
- <literal>boolean</literal> クラス (あるいはインターフェイス)
- のインスタンスであると宣言したことになります。
- </para>
- <para>
- <example>
- <programlisting role="php">
- <![CDATA[
- <?php
- function test(boolean $param) {}
- test(true);
- ?>
- ]]>
- </programlisting>
- &example.outputs;
- <screen>
- <![CDATA[
- Fatal error: Uncaught TypeError: Argument 1 passed to test() must be an instance of boolean, boolean given, called in - on line 1 and defined in -:1
- ]]>
- </screen>
- </example>
- </para>
- </warning>
- </sect3>
-
- <sect3 xml:id="functions.arguments.type-declaration.examples">
- &reftitle.examples;
- <example>
- <title>クラスの型宣言の基本例</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-class C {}
-class D extends C {}
-
-// これは C を継承していません。
-class E {}
-
-function f(C $c) {
- echo get_class($c)."\n";
-}
-
-f(new C);
-f(new D);
-f(new E);
-?>
-]]>
- </programlisting>
- &example.outputs;
- <screen>
-<![CDATA[
-C
-D
-
-Fatal error: Uncaught TypeError: Argument 1 passed to f() must be an instance of C, instance of E given, called in - on line 14 and defined in -:8
-Stack trace:
-#0 -(14): f(Object(E))
-#1 {main}
- thrown in - on line 8
-]]>
- </screen>
- </example>
-
- <example>
- <title>インターフェイスの型宣言の基本例</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-interface I { public function f(); }
-class C implements I { public function f() {} }
-
-// これは I を実装していません。
-class E {}
-
-function f(I $i) {
- echo get_class($i)."\n";
-}
-
-f(new C);
-f(new E);
-?>
-]]>
- </programlisting>
- &example.outputs;
- <screen>
-<![CDATA[
-C
-
-Fatal error: Uncaught TypeError: Argument 1 passed to f() must implement interface I, instance of E given, called in - on line 13 and defined in -:8
-Stack trace:
-#0 -(13): f(Object(E))
-#1 {main}
- thrown in - on line 8
-]]>
- </screen>
- </example>
-
- <example>
- <title>型付きパラメータを参照渡しする例</title>
- <simpara>
- 参照パラメータに宣言された型は、関数が返る時ではなく、
- 関数に入る時にチェックされます。よって、関数が返った後は、
- 引数の型は変わっている可能性があります。
- </simpara>
- <programlisting role="php">
-<![CDATA[
-<?php
-function array_baz(array &$param)
-{
- $param = 1;
-}
-$var = [];
-array_baz($var);
-var_dump($var);
-array_baz($var);
-?>
-]]>
- </programlisting>
- &example.outputs.similar;
- <screen>
-<![CDATA[
-int(1)
-
-Fatal error: Uncaught TypeError: Argument 1 passed to array_baz() must be of the type array, int given, called in %s on line %d
-]]>
- </screen>
- </example>
-
- <example>
- <title>Null を許可する型宣言</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-class C {}
-
-function f(C $c = null) {
- var_dump($c);
-}
-
-f(new C);
-f(null);
-?>
-]]>
- </programlisting>
- &example.outputs;
- <screen>
-<![CDATA[
-object(C)#1 (0) {
-}
-NULL
-]]>
- </screen>
- </example>
- </sect3>
-
- <sect3 xml:id="functions.arguments.type-declaration.strict">
- <title>強い型付け</title>
-
- <para>
- デフォルトでは、間違った型を渡された場合でも、可能な限り期待されている型に変換します。
- たとえば、<type>string</type> を想定している関数のパラメータに
- <type>int</type> が渡された場合は、その値を
- <type>string</type> 型として受け取ります。
- </para>
-
- <para>
- ファイル単位で厳密な型チェックを有効にすることもできます。
- この場合は、宣言されたとおりの型でない限りは受け付けず、
- <classname>TypeError</classname> をスローします。
- ただし、<type>float</type> が指定されているところに
- <type>int</type> を渡した場合だけは例外です。
- 組み込み関数内からの関数呼び出しは、
- <literal>strict_types</literal> 宣言の影響を受けません。
- </para>
-
- <para>
- 厳密な型チェックを有効にするには、&declare; 文を用いて
- <literal>strict_types</literal> を宣言します。
- </para>
-
- <caution>
- <para>
- 厳密な型チェックを有効にすると、
- <link linkend="functions.returning-values.type-declaration">戻り値の型宣言</link>
- にも影響を及ぼします。
- </para>
- </caution>
-
- <note>
- <para>
- 厳密な型チェックが適用されるのは、それを有効にしたファイル
- <emphasis>の中からの</emphasis>関数呼び出しだけです。
- そのファイル内で宣言されている関数に適用されるわけではありません。
- 厳密な型チェックを有効にしていないファイルから、
- 厳密な型チェックを有効にしたファイル内で定義された関数を呼び出した場合は、
- 呼び出し元の設定 (弱い型チェック) が適用されて、自動的に型変換を行います。
- </para>
- </note>
-
- <note>
- <para>
- 厳密な型チェックはスカラー型宣言に対してのみ定義されるものです。
- </para>
- </note>
-
- <example>
- <title>厳密な型チェック</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-declare(strict_types=1);
-
-function sum(int $a, int $b) {
- return $a + $b;
-}
-
-var_dump(sum(1, 2));
-var_dump(sum(1.5, 2.5));
-?>
-]]>
- </programlisting>
- &example.outputs;
- <screen>
-<![CDATA[
-int(3)
-
-Fatal error: Uncaught TypeError: Argument 1 passed to sum() must be of the type integer, float given, called in - on line 9 and defined in -:4
-Stack trace:
-#0 -(9): sum(1.5, 2.5)
-#1 {main}
- thrown in - on line 4
-]]>
- </screen>
- </example>
-
- <example>
- <title>弱い型チェック</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-function sum(int $a, int $b) {
- return $a + $b;
-}
-
-var_dump(sum(1, 2));
-
-// これらは integer 型として扱われます。出力例に注目!
-var_dump(sum(1.5, 2.5));
-?>
-]]>
- </programlisting>
- &example.outputs;
- <screen>
-<![CDATA[
-int(3)
-int(3)
-]]>
- </screen>
- </example>
-
- <example>
- <title><classname>TypeError</classname> の捕捉</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-declare(strict_types=1);
-
-function sum(int $a, int $b) {
- return $a + $b;
-}
-
-try {
- var_dump(sum(1, 2));
- var_dump(sum(1.5, 2.5));
-} catch (TypeError $e) {
- echo 'Error: '.$e->getMessage();
-}
-?>
-]]>
- </programlisting>
- &example.outputs;
- <screen>
-<![CDATA[
-int(3)
-Error: Argument 1 passed to sum() must be of the type integer, float given, called in - on line 10
-]]>
- </screen>
- </example>
- </sect3>
- </sect2>
-
<sect2 xml:id="functions.variable-arg-list">
<title>可変長引数リスト</title>
@@ -857,10 +451,10 @@
<para>
<literal>...</literal> トークンの前に、
- <link linkend="language.oop5.typehinting">タイプヒント</link> を付加することもできます。
- タイプヒントがある場合、<literal>...</literal> が取り込むすべての引数はそのヒントに従わなければいけません。
+ <link linkend="language.types.declarations">型宣言</link> を付加することもできます。
+ 型宣言がある場合、<literal>...</literal> が取り込むすべての引数はその型に従わなければいけません。
<example>
- <title>タイプヒントつきの可変長引数</title>
+ <title>型宣言つきの可変長引数</title>
<programlisting role="php">
<![CDATA[
<?php
@@ -972,200 +566,60 @@
echo square(4); // '16'を出力
?>
]]>
- </programlisting>
- </example>
- </para>
- <para>
- 複数の値を返すことはできませんが、リストを返すことにより
- 同じ効果を得ることができます。
- </para>
- <para>
- <example>
- <title>複数の値を得るために配列を返す</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-function small_numbers()
-{
- return array (0, 1, 2);
-}
-list ($zero, $one, $two) = small_numbers();
-?>
-]]>
- </programlisting>
- </example>
- </para>
- <para>
- 関数からリファレンスを返すには、リファレンス演算子 & を関数宣
- 言部および変数への返り値を代入する際の両方で使用する必要があります。
- </para>
- <para>
- <example>
- <title>関数からリファレンスを返す</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-function &returns_reference()
-{
- return $someref;
-}
-
-$newref =& returns_reference();
-?>
-]]>
- </programlisting>
- </example>
- </para>
- <simpara>
- リファレンスに関するさらに詳しい情報が<link
- linkend="language.references">リファレンスの説明</link>にあります。
- </simpara>
- </sect2>
-
- <sect2 xml:id="functions.returning-values.type-declaration">
- <title>戻り値の型宣言</title>
-
- <para>
- <link linkend="functions.arguments.type-declaration">引数の型宣言</link>
- と同様に、戻り値の型宣言は、関数から戻される値の型を指定します。
- 戻り値の型宣言で使える
- <link linkend="functions.arguments.type-declaration.types">型</link>
- は、引数の型宣言で使えるものと同じです。
- </para>
-
- <para>
- <link linkend="functions.arguments.type-declaration.strict">厳密な型チェック</link>
- は、戻り値の型宣言にも影響を及ぼします。デフォルトの弱い型付けでは、
- もし戻り値の型が正しいものではなくても、自動的に型変換を行います。
- この型変換が許されない場合
- (たとえば、&array; を返す場合に、関数が &integer; を返している場合) は、
- <classname>TypeError</classname> が発生します。
- 強い型付けの場合は、戻り値の型が正確に一致しなければならず、違っている場合は
- <classname>TypeError</classname> が発生します。
- </para>
-
- <para>
- PHP 7.1.0 以降では、
- 返り値の型を <type>void</type>
- と宣言していない場合に引数がないreturn文を使うと、
- <constant>E_COMPILE_ERROR</constant> が発生するようになりました。
- これは、そのreturn文に到達しない場合であっても同じです。
- </para>
-
- <para>
- PHP 7.1.0 以降では、型の名前の前にクエスチョンマーク
- (<literal>?</literal>) を付けることによって、
- 戻り値の値が nullable とマークできるようになりました。
- これは、関数の戻り地の型が特定の型か、&null; を返すかの印になります。
- </para>
-
- <note>
- <!-- TODO Link to covariance section -->
+ </programlisting>
+ </example>
+ </para>
+
<para>
- 親クラスのメソッドをオーバーライドする場合、子クラスのメソッドの戻り値の型は、
- 親クラスで宣言されたものと同じでなければいけません。
- 親クラスのメソッドが戻り値の型を宣言していない場合は、
- 子クラスのメソッドで型宣言をすることもできます。
+ 関数は複数の値を返すことは出来ませんが、
+ 配列を返すことで似たような結果を得ることができます。
</para>
- </note>
+ <para>
- <sect3 xml:id="functions.returning-values.type-declaration.examples">
- &reftitle.examples;
-
- <example>
- <title>戻り値の型宣言の基本例</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-function sum($a, $b): float {
- return $a + $b;
-}
-
-// 戻り値が float となることに注目
-var_dump(sum(1, 2));
-?>
-]]>
- </programlisting>
- &example.outputs;
- <screen>
-<![CDATA[
-float(3)
-]]>
- </screen>
- </example>
-
<example>
- <title>強い型付けの例</title>
+ <title>複数の値を得るために配列を返す例</title>
<programlisting role="php">
<![CDATA[
<?php
-declare(strict_types=1);
-
-function sum($a, $b): int {
- return $a + $b;
+function small_numbers()
+{
+ return array (0, 1, 2);
}
-var_dump(sum(1, 2));
-var_dump(sum(1, 2.5));
+list ($zero, $one, $two) = small_numbers();
?>
]]>
</programlisting>
- &example.outputs;
- <screen>
-<![CDATA[
-int(3)
-
-Fatal error: Uncaught TypeError: Return value of sum() must be of the type integer, float returned in - on line 5 in -:5
-Stack trace:
-#0 -(9): sum(1, 2.5)
-#1 {main}
- thrown in - on line 5
-]]>
- </screen>
</example>
+ </para>
+ <para>
+ 関数からリファレンスを返すためには、
+ 関数宣言と返り値を代入する変数に対して、
+ リファレンス演算子 & を使います:
+ </para>
+ <para>
<example>
- <title>オブジェクトを返す例</title>
+ <title>関数からリファレンスを返す</title>
<programlisting role="php">
<![CDATA[
<?php
-class C {}
-
-function getC(): C {
- return new C;
+function &returns_reference()
+{
+ return $someref;
}
-var_dump(getC());
+$newref =& returns_reference();
?>
]]>
</programlisting>
- &example.outputs;
- <screen>
-<![CDATA[
-object(C)#1 (0) {
-}
-]]>
- </screen>
</example>
- <example>
- <title>Nullable な返り値の型宣言 (PHP 7.1.0 以降)</title>
- <programlisting role="php">
-<![CDATA[
-<?php
-function get_item(): ?string {
- if (isset($_GET['item'])) {
- return $_GET['item'];
- } else {
- return null;
- }
-}
-?>
-]]>
- </programlisting>
- </example>
-
- </sect3>
+ </para>
+ <simpara>
+ リファレンスに関する詳細は、<link
+ linkend="language.references">リファレンスの説明</link> を参照して下さい。
+ </simpara>
</sect2>
</sect1>
Modified: phpdoc/ja/trunk/language/oop5/interfaces.xml
===================================================================
--- phpdoc/ja/trunk/language/oop5/interfaces.xml 2020-11-12 23:53:01 UTC (rev 351370)
+++ phpdoc/ja/trunk/language/oop5/interfaces.xml 2020-11-13 00:31:04 UTC (rev 351371)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 348385 Maintainer: hirokawa Status: ready -->
+<!-- EN-Revision: 351365 Maintainer: hirokawa Status: ready -->
<!-- CREDITS: shimooka,takagi,mumumu -->
<sect1 xml:id="language.oop5.interfaces" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
@@ -225,7 +225,7 @@
インターフェイスとタイプヒンティングを組み合わせると、
特定のオブジェクトに特定のメソッドをうまく持たせることができます。
<link linkend="language.operators.type">instanceof</link> 演算子および
- <link linkend="language.oop5.typehinting">タイプヒンティング</link>
+ <link linkend="language.types.declarations">型宣言</link>
を参照ください。
</para>
</sect2>
Deleted: phpdoc/ja/trunk/language/oop5/typehinting.xml
===================================================================
--- phpdoc/ja/trunk/language/oop5/typehinting.xml 2020-11-12 23:53:01 UTC (rev 351370)
+++ phpdoc/ja/trunk/language/oop5/typehinting.xml 2020-11-13 00:31:04 UTC (rev 351371)
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- $Revision$ -->
-<!-- EN-Revision: 337365 Maintainer: takagi Status: ready -->
-<!-- CREDITS: hirokawa -->
-
-<sect1 xml:id="language.oop5.typehinting" xmlns="http://docbook.org/ns/docbook">
- <title>タイプヒンティング</title>
-
- <para>
- このドキュメントは
- <link linkend="functions.arguments.type-declaration">関数のページ</link>
- に移動しました。
- </para>
-</sect1>
-
-<!-- Keep this comment at the end of the file
-Local variables:
-mode: sgml
-sgml-omittag:t
-sgml-shorttag:t
-sgml-minimize-attributes:nil
-sgml-always-quote-attributes:t
-sgml-indent-step:1
-sgml-indent-data:t
-indent-tabs-mode:nil
-sgml-parent-document:nil
-sgml-default-dtd-file:"~/.phpdoc/manual.ced"
-sgml-exposed-tags:nil
-sgml-local-catalogs:nil
-sgml-local-ecat-files:nil
-End:
-vim600: syn=xml fen fdm=syntax fdl=2 si
-vim: et tw=78 syn=sgml
-vi: ts=1 sw=1
--->
Modified: phpdoc/ja/trunk/language/oop5.xml
===================================================================
--- phpdoc/ja/trunk/language/oop5.xml 2020-11-12 23:53:01 UTC (rev 351370)
+++ phpdoc/ja/trunk/language/oop5.xml 2020-11-13 00:31:04 UTC (rev 351371)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 351112 Maintainer: hirokawa Status: ready -->
+<!-- EN-Revision: 351365 Maintainer: hirokawa Status: ready -->
<!-- CREDITS: mumumu -->
<chapter xml:id="language.oop5" xmlns="http://docbook.org/ns/docbook">
@@ -16,8 +16,7 @@
<link linkend="language.oop5.final">final</link> クラスやメソッド、
新たな <link linkend="language.oop5.magic">マジックメソッド</link>、
<link linkend="language.oop5.interfaces">インターフェイス</link>、
- <link linkend="language.oop5.cloning">クローン</link> そして
- <link linkend="language.oop5.typehinting">型宣言</link>
+ <link linkend="language.oop5.cloning">クローン</link>
などがあります。
</para>
<para>
@@ -48,7 +47,6 @@
&language.oop5.final;
&language.oop5.cloning;
&language.oop5.object-comparison;
- &language.oop5.typehinting;
&language.oop5.late-static-bindings;
&language.oop5.references;
&language.oop5.serialization;
Added: phpdoc/ja/trunk/language/types/declarations.xml
===================================================================
--- phpdoc/ja/trunk/language/types/declarations.xml (rev 0)
+++ phpdoc/ja/trunk/language/types/declarations.xml 2020-11-13 00:31:04 UTC (rev 351371)
@@ -0,0 +1,817 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- $Revision$ -->
+<!-- EN-Revision: 351366 Maintainer: mumumu Status: working -->
+
+<sect1 xml:id="language.types.declarations">
+ <title>型宣言</title>
+
+ <para>
+ 関数のパラメータや戻り値、PHP 7.4.0 以降では
+ クラスのプロパティに対して型を宣言することができます。
+ これによって、その値が特定の型であることを保証できます。
+ その型でない場合は、<classname>TypeError</classname> がスローされます。
+ </para>
+
+ <!-- Find better place where to put this note -->
+ <note>
+ <!-- TODO Link to covariance section -->
+ <para>
+ 親クラスのメソッドをオーバーライドする場合、
+ 子クラスのメソッドは、
+ 親クラスで宣言された戻り値の型のいずれかに一致させなければなりません。
+ 親クラスが戻り値の型を宣言していない場合、
+ 子クラスのメソッドもそうしなければなりません。
+ </para>
+ </note>
+
+ <sect2 xml:id="language.types.declarations.base">
+ <title>基本的な型</title>
+ <informaltable>
+ <tgroup cols="3">
+ <thead>
+ <row>
+ <entry>&Type;</entry>
+ <entry>&Description;</entry>
+ <entry>&Version;</entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>クラス/インターフェイス の名前</entry>
+ <entry>
+ 値が、指定したクラスやインターフェイスのインスタンスでなければいけません。
+ </entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><type>self</type></entry>
+ <entry>
+ 値が、そのメソッドが定義されているクラスと同じクラスのインスタンスでなければいけません。
+ クラスの内部でのみ使えます。
+ </entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><type>array</type></entry>
+ <entry>
+ 値が、配列でなければいけません。
+ </entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><type>callable</type></entry>
+ <entry>
+ 値が、<type>callable</type> でなければいけません。
+ クラスのプロパティの型では宣言できません。
+ </entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><type>bool</type></entry>
+ <entry>
+ 値が、bool 値でなければいけません。
+ </entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><type>float</type></entry>
+ <entry>
+ 値が、float でなければいけません。
+ </entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><type>int</type></entry>
+ <entry>
+ 値が、int でなければいけません。
+ </entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><type>string</type></entry>
+ <entry>
+ 値が、文字列でなければいけません。
+ </entry>
+ <entry></entry>
+ </row>
+ <row>
+ <entry><type>iterable</type></entry>
+ <entry>
+ 値が、配列か、<classname>Traversable</classname> のインスタンスでなければなりません。
+ </entry>
+ <entry>PHP 7.1.0 以降</entry>
+ </row>
+ <row>
+ <entry><type>object</type></entry>
+ <entry>
+ 値が、<type>object</type> でなければなりません。
+ </entry>
+ <entry>PHP 7.2.0 以降</entry>
+ </row>
+ <row>
+ <entry><type>mixed</type></entry>
+ <entry>
+ 値は、あらゆる値であることができます。
+ </entry>
+ <entry>PHP 8.0.0 以降</entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
+
+ <warning>
+ <para>
+ 上記のスカラー型のエイリアスはサポートされていません。
+ つまり、これらはクラスやインターフェイスの名前として扱われているということです。
+ たとえば、型の宣言に <literal>boolean</literal> を使った場合、
+ 値が <literal>boolean</literal>
+ クラスまたはインターフェイスのインスタンスであることが要求されます。
+ <type>bool</type> 型ではありません。
+ </para>
+ <para>
+ <example>
+ <programlisting role="php">
+<![CDATA[
+<?php
+ function test(boolean $param) {}
+ test(true);
+?>
+]]>
+ </programlisting>
+ &example.outputs.8;
+ <screen>
+<![CDATA[
+Warning: "boolean" will be interpreted as a class name. Did you mean "bool"? Write "\boolean" to suppress this warning in /in/9YrUX on line 2
+
+Fatal error: Uncaught TypeError: test(): Argument #1 ($param) must be of type boolean, bool given, called in - on line 3 and defined in -:2
+Stack trace:
+#0 -(3): test(true)
+#1 {main}
+ thrown in - on line 2
+]]>
+ </screen>
+ </example>
+ </para>
+ </warning>
+
+ <sect3 xml:id="language.types.declarations.examples">
+ &reftitle.examples;
+ <example>
+ <title>クラスによる型宣言の基本</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+class C {}
+class D extends C {}
+
+// This doesn't extend C.
+class E {}
+
+function f(C $c) {
+ echo get_class($c)."\n";
+}
+
+f(new C);
+f(new D);
+f(new E);
+?>
+]]>
+ </programlisting>
+ &example.outputs.8;
+ <screen>
+<![CDATA[
+C
+D
+
+Fatal error: Uncaught TypeError: f(): Argument #1 ($c) must be of type C, E given, called in /in/gLonb on line 14 and defined in /in/gLonb:8
+Stack trace:
+#0 -(14): f(Object(E))
+#1 {main}
+ thrown in - on line 8
+]]>
+ </screen>
+ </example>
+
+ <example>
+ <title>インターフェイスによる型宣言の基本</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+interface I { public function f(); }
+class C implements I { public function f() {} }
+
+// This doesn't implement I.
+class E {}
+
+function f(I $i) {
+ echo get_class($i)."\n";
+}
+
+f(new C);
+f(new E);
+?>
+]]>
+ </programlisting>
+ &example.outputs.8;
+ <screen>
+<![CDATA[
+C
+
+Fatal error: Uncaught TypeError: f(): Argument #1 ($i) must be of type I, E given, called in - on line 13 and defined in -:8
+Stack trace:
+#0 -(13): f(Object(E))
+#1 {main}
+ thrown in - on line 8
+]]>
+ </screen>
+ </example>
+
+ <example>
+ <title>基本的な戻り値の型宣言</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+function sum($a, $b): float {
+ return $a + $b;
+}
+
+// Note that a float will be returned.
+var_dump(sum(1, 2));
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+float(3)
+]]>
+ </screen>
+ </example>
+
+ <example>
+ <title>オブジェクトを返す</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+class C {}
+
+function getC(): C {
+ return new C;
+}
+
+var_dump(getC());
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+object(C)#1 (0) {
+}
+]]>
+ </screen>
+ </example>
+ </sect3>
+ </sect2>
+
+ <sect2 xml:id="language.types.declarations.nullable">
+ <title>Nullを許容する型宣言</title>
+
+ <para>
+ PHP 7.1.0 以降では、型の名前の前にクエスチョンマーク
+ (<literal>?</literal>) を付けることで、null を許容する印を付けられるようになりました。
+ こうすることで、その値の型が指定されたものか、&null; であることを指定できます。
+ </para>
+
+ <para>
+ <example>
+ <title>Nullを許容する型宣言</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+class C {}
+
+function f(?C $c) {
+ var_dump($c);
+}
+
+f(new C);
+f(null);
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+object(C)#1 (0) {
+}
+NULL
+]]>
+ </screen>
+ </example>
+
+ <example>
+ <title>Null を許容する戻り値の型宣言</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+function get_item(): ?string {
+ if (isset($_GET['item'])) {
+ return $_GET['item'];
+ } else {
+ return null;
+ }
+}
+?>
+]]>
+ </programlisting>
+ </example>
+ </para>
+
+ <note>
+ <para>
+ PHP 7.1.0 より前のバージョンでは、
+ デフォルト値に <literal>null</literal> を指定することで
+ null を許容する引数を指定することが出来ました。
+ これは、継承関係を破壊するので推奨できません。
+ </para>
+ <example>
+ <title>引数にnullを許容する古いやり方</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+class C {}
+
+function f(C $c = null) {
+ var_dump($c);
+}
+
+f(new C);
+f(null);
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+object(C)#1 (0) {
+}
+NULL
+]]>
+ </screen>
+ </example>
+ </note>
+ </sect2>
+
+ <!-- to be translated -->
+ <sect2 xml:id="language.types.declarations.union">
+ <title>Union types</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.
+ </para>
+
+ <sect3 xml:id="language.types.declarations.union.nullable">
+ <title>Nullable union types</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>.
+ </para>
+
+ <caution>
+ <simpara>
+ <literal>null</literal> cannot be used as a standalone type.
+ </simpara>
+ </caution>
+ </sect3>
+
+ <sect3 xml:id="language.types.declarations.union.false">
+ <title>false pseudo-type</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>.
+ </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.
+ </simpara>
+ </caution>
+ <caution>
+ <simpara>
+ The <literal>true</literal> literal type does <emphasis>not</emphasis>
+ exist.
+ </simpara>
+ </caution>
+ </sect3>
+
+ <sect3 xml:id="language.types.declarations.union.redundant">
+ <title>Duplicate and redundant types</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:
+
+ <itemizedlist>
+ <listitem>
+ <simpara>
+ Each name-resolved type may only occur once. Types such as
+ <literal>int|string|INT</literal> result in an error.
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ If <type>bool</type> is used, <type>false</type> cannot be used additionally.
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ If <type>object</type> is used, class types cannot be used additionally.
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ If <type>iterable</type> is used, <type>array</type>
+ and <classname>Traversable</classname> cannot be used additionally.
+ </simpara>
+ </listitem>
+ </itemizedlist>
+ </para>
+
+ <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>.
+
+ <informalexample>
+ <programlisting role="php">
+<![CDATA[
+<?php
+function foo(): int|INT {} // Disallowed
+function foo(): bool|false {} // Disallowed
+
+use A as B;
+function foo(): A|B {} // Disallowed ("use" is part of name resolution)
+
+class_alias('X', 'Y');
+function foo(): X|Y {} // Allowed (redundancy is only known at runtime)
+?>
+]]>
+ </programlisting>
+ </informalexample>
+ </para>
+ </sect3>
+
+ </sect2>
+
+ <sect2 xml:id="language.types.declarations.return-only">
+ <title>Return only types</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.
+ </para>
+ </sect3>
+
+ <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.
+ </para>
+ </sect3>
+ </sect2>
+
+ <sect2 xml:id="language.types.declarations.strict">
+ <title>Strict typing</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>.
+ </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.
+ </para>
+
+ <warning>
+ <simpara>
+ Function calls from within internal functions will not be affected by
+ the <literal>strict_types</literal> declaration.
+ </simpara>
+ </warning>
+
+ <para>
+ To enable strict mode, the &declare; statement is used with the
+ <literal>strict_types</literal> declaration:
+ </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.
+ </para>
+ </note>
+
+ <note>
+ <para>
+ Strict typing is only defined for scalar type declarations.
+ </para>
+ </note>
+
+ <example>
+ <title>Strict typing for arguments values</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+declare(strict_types=1);
+
+function sum(int $a, int $b) {
+ return $a + $b;
+}
+
+var_dump(sum(1, 2));
+var_dump(sum(1.5, 2.5));
+?>
+]]>
+ </programlisting>
+ &example.outputs.8;
+ <screen>
+<![CDATA[
+int(3)
+
+Fatal error: Uncaught TypeError: sum(): Argument #1 ($a) must be of type int, float given, called in - on line 9 and defined in -:4
+Stack trace:
+#0 -(9): sum(1.5, 2.5)
+#1 {main}
+ thrown in - on line 4
+]]>
+ </screen>
+ </example>
+
+ <example>
+ <title>Coercive typing for argument values</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+function sum(int $a, int $b) {
+ return $a + $b;
+}
+
+var_dump(sum(1, 2));
+
+// These will be coerced to integers: note the output below!
+var_dump(sum(1.5, 2.5));
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+int(3)
+int(3)
+]]>
+ </screen>
+ </example>
+
+ <example>
+ <title>Strict typing for return values</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+declare(strict_types=1);
+
+function sum($a, $b): int {
+ return $a + $b;
+}
+
+var_dump(sum(1, 2));
+var_dump(sum(1, 2.5));
+?>
+]]>
+ </programlisting>
+ &example.outputs;
+ <screen>
+<![CDATA[
+int(3)
+
+Fatal error: Uncaught TypeError: sum(): Return value must be of type int, float returned in -:5
+Stack trace:
+#0 -(9): sum(1, 2.5)
+#1 {main}
+ thrown in - on line 5
+]]>
+ </screen>
+ </example>
+ </sect2>
+
+ <sect2 xml:id="language.types.declarations.union.coercive">
+ <title>Coercive typing with union types</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:
+
+ <orderedlist>
+ <listitem>
+ <simpara>
+ <type>int</type>
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ <type>float</type>
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ <type>string</type>
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ <type>bool</type>
+ </simpara>
+ </listitem>
+ </orderedlist>
+
+ 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.
+ </para>
+
+ <caution>
+ <para>
+ As an exception, if the value is a string and both int and float are part
+ of the union, the preferred type is determined by the existing
+ “numeric string” semantics.
+ For example, for <literal>"42"</literal> <type>int</type> is chosen,
+ while for <literal>"42.0"</literal> <type>float</type> is chosen.
+ </para>
+ </caution>
+
+ <note>
+ <para>
+ Types that are not part of the above preference list are not eligible
+ targets for implicit coercion. In particular no implicit coercions to
+ the <literal>null</literal> and <literal>false</literal> types occur.
+ </para>
+ </note>
+
+ <example>
+ <title>Example of types being coerced into a type part of the union</title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+// int|string
+42 --> 42 // exact type
+"42" --> "42" // exact type
+new ObjectWithToString --> "Result of __toString()"
+ // object never compatible with int, fall back to string
+42.0 --> 42 // float compatible with int
+42.1 --> 42 // float compatible with int
+1e100 --> "1.0E+100" // float too large for int type, fall back to string
+INF --> "INF" // float too large for int type, fall back to string
+true --> 1 // bool compatible with int
+[] --> TypeError // array not compatible with int or string
+
+// int|float|bool
+"45" --> 45 // int numeric string
+"45.0" --> 45.0 // float numeric string
+
+"45X" --> true // not numeric string, fall back to bool
+"" --> false // not numeric string, fall back to bool
+"X" --> true // not numeric string, fall back to bool
+[] --> TypeError // array not compatible with int, float or bool
+?>
+]]>
+ </programlisting>
+ </example>
+ </sect2>
+
+<!-- TODO figure out what do to with these things -->
+ <sect2 xml:id="language.types.declarations.misc">
+ <title>Misc</title>
+ <example>
+ <title>Typed pass-by-reference Parameters</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[
+<?php
+function array_baz(array &$param)
+{
+ $param = 1;
+}
+$var = [];
+array_baz($var);
+var_dump($var);
+array_baz($var);
+?>
+]]>
+ </programlisting>
+ &example.outputs.8;
+ <screen>
+<![CDATA[
+int(1)
+
+Fatal error: Uncaught TypeError: array_baz(): Argument #1 ($param) must be of type array, int given, called in - on line 9 and defined in -:2
+Stack trace:
+#0 -(9): array_baz(1)
+#1 {main}
+ thrown in - on line 2
+]]>
+ </screen>
+ </example>
+
+ <example>
+ <title>Catching <classname>TypeError</classname></title>
+ <programlisting role="php">
+<![CDATA[
+<?php
+declare(strict_types=1);
+
+function sum(int $a, int $b) {
+ return $a + $b;
+}
+
+try {
+ var_dump(sum(1, 2));
+ var_dump(sum(1.5, 2.5));
+} catch (TypeError $e) {
+ echo 'Error: ', $e->getMessage();
+}
+?>
+]]>
+ </programlisting>
+ &example.outputs.8;
+ <screen>
+<![CDATA[
+int(3)
+Error: sum(): Argument #1 ($a) must be of type int, float given, called in - on line 10
+]]>
+ </screen>
+ </example>
+ </sect2>
+
+</sect1>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:t
+sgml-shorttag:t
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:1
+sgml-indent-data:t
+indent-tabs-mode:nil
+sgml-parent-document:nil
+sgml-default-dtd-file:"~/.phpdoc/manual.ced"
+sgml-exposed-tags:nil
+sgml-local-catalogs:nil
+sgml-local-ecat-files:nil
+End:
+vim600: syn=xml fen fdm=syntax fdl=2 si
+vim: et tw=78 syn=sgml
+vi: ts=1 sw=1
+-->
Property changes on: phpdoc/ja/trunk/language/types/declarations.xml
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Id Rev Revision Date LastChangedDate LastChangedRevision Author LastChangedBy HeadURL URL
\ No newline at end of property
Modified: phpdoc/ja/trunk/language/types.xml
===================================================================
--- phpdoc/ja/trunk/language/types.xml 2020-11-12 23:53:01 UTC (rev 351370)
+++ phpdoc/ja/trunk/language/types.xml 2020-11-13 00:31:04 UTC (rev 351371)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 351133 Maintainer: hirokawa Status: ready -->
+<!-- EN-Revision: 351365 Maintainer: hirokawa Status: ready -->
<!-- CREDITS: takagi,shimooka,mumumu -->
<chapter xml:id="language.types" xmlns="http://docbook.org/ns/docbook">
<title>型</title>
@@ -196,6 +196,7 @@
&language.types.resource;
&language.types.null;
&language.types.callable;
+ &language.types.declarations;
&language.types.pseudo-types;
&language.types.type-juggling;
Modified: phpdoc/ja/trunk/language-snippets.ent
===================================================================
--- phpdoc/ja/trunk/language-snippets.ent 2020-11-12 23:53:01 UTC (rev 351370)
+++ phpdoc/ja/trunk/language-snippets.ent 2020-11-13 00:31:04 UTC (rev 351371)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 351354 Maintainer: takagi Status: working -->
+<!-- EN-Revision: 351365 Maintainer: takagi Status: working -->
<!-- Credits: hirokawa,haruki,shimooka,mumumu -->
<!ENTITY installation.enabled.disable 'この拡張モジュールはデフォルトで有効になっています。無効にしたい場合は、次のオプションを指定してコンパイルします。'>
@@ -487,6 +487,10 @@
<!ENTITY example.outputs.73 '<para xmlns="http://docbook.org/ns/docbook">上の例の PHP 7.3 での出力は、このようになります。</para>'>
+<!ENTITY example.outputs.8 '<para xmlns="http://docbook.org/ns/docbook">上の例の PHP 8 での出力は、このようになります。:</para>'>
+
+<!ENTITY example.outputs.80 '<para xmlns="http://docbook.org/ns/docbook">上の例の PHP 8.0 での出力は、このようになります。:</para>'>
+
<!ENTITY example.outputs.32bit '<para xmlns="http://docbook.org/ns/docbook">上の例の 32 ビットマシンでの出力は、このようになります。</para>'>
<!ENTITY example.outputs.64bit '<para xmlns="http://docbook.org/ns/docbook">上の例の 64 ビットマシンでの出力は、このようになります。</para>'>
Modified: phpdoc/ja/trunk/reference/filesystem/functions/file-get-contents.xml
===================================================================
--- phpdoc/ja/trunk/reference/filesystem/functions/file-get-contents.xml 2020-11-12 23:53:01 UTC (rev 351370)
+++ phpdoc/ja/trunk/reference/filesystem/functions/file-get-contents.xml 2020-11-13 00:31:04 UTC (rev 351371)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
-<!-- EN-Revision: 351135 Maintainer: hirokawa Status: ready -->
+<!-- EN-Revision: 351365 Maintainer: hirokawa Status: ready -->
<!-- CREDITS: shimooka,mumumu -->
<refentry xmlns="http://docbook.org/ns/docbook" xml:id="function.file-get-contents" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
@@ -59,7 +59,7 @@
を使用して <link linkend="ini.include-path">インクルードパス</link>
から探すことができます。
この定数を使うことは、<link
- linkend="functions.arguments.type-declaration.strict">強い型付け</link>
+ linkend="language.types.declarations.strict">強い型付け</link>
が有効になっている場合は不可能です。なぜなら、
<constant>FILE_USE_INCLUDE_PATH</constant> が <type>int</type> だからです。
&true; を代わりに使いましょう。