1
1
<?xml version =" 1.0" encoding =" utf-8" ?>
2
2
<!-- $Revision$ -->
3
- <!-- EN-Revision: 86e6094e86b84a51d00ab217ac50ce8dde33d82a Maintainer: hirokawa Status: ready -->
3
+ <!-- EN-Revision: 2aaaf1967f2510471b694daf8e41a419fc98b751 Maintainer: hirokawa Status: ready -->
4
4
<!-- CREDITS: takagi -->
5
5
<refentry xml : id =" function.exit" xmlns =" http://docbook.org/ns/docbook" >
6
6
<refnamediv >
7
7
<refname >exit</refname >
8
- <refpurpose >メッセージを出力し、現在のスクリプトを終了する </refpurpose >
8
+ <refpurpose >ステータスコードかメッセージを返して現在のスクリプトを終了する </refpurpose >
9
9
</refnamediv >
10
-
10
+
11
11
<refsect1 role =" description" >
12
12
&reftitle.description;
13
13
<methodsynopsis >
14
- <type >void</type ><methodname >exit</methodname >
15
- <methodparam choice =" opt" ><type >string</type ><parameter >status</parameter ></methodparam >
16
- </methodsynopsis >
17
- <methodsynopsis >
18
- <type >void</type ><methodname >exit</methodname >
19
- <methodparam ><type >int</type ><parameter >status</parameter ></methodparam >
14
+ <type >never</type ><methodname >exit</methodname >
15
+ <methodparam choice =" opt" ><type class =" union" ><type >string</type ><type >int</type ></type ><parameter >status</parameter ><initializer >0</initializer ></methodparam >
20
16
</methodsynopsis >
21
- <para >
17
+ <simpara >
22
18
スクリプトの実行を終了します。
23
19
<link linkend =" function.register-shutdown-function" >シャットダウン関数</link >
24
20
や <link linkend =" language.oop5.decon.destructor" >オブジェクトのデストラクタ</link >
25
- は、<literal >exit</literal > がコールされた場合にも実行されます。
26
- </para >
27
- <para >
28
- <literal >exit</literal > は言語構造です。
29
- <parameter >status</parameter > を指定しない場合は括弧なしでコールできます。
30
- </para >
21
+ は、<function >exit</function > がコールされた場合にも実行されます。
22
+ ただし、&finally; ブロックは実行されません。
23
+ </simpara >
24
+ <simpara >
25
+ 終了コード <literal >0</literal > は、そのタスクでプログラムが成功したことを表します。
26
+ 他の値は、実行中に何らかのエラーが発生したことを表します。
27
+ </simpara >
28
+ <simpara >
29
+ <function >exit</function > は特殊な関数です。
30
+ パーサーに専用のトークンがあるため、文として使用して(つまり、括弧なしで)、
31
+ デフォルトのステータスコードでスクリプトを終了させることができます。
32
+ </simpara >
33
+ <caution >
34
+ <simpara >
35
+ グローバルな <function >exit</function > を無効にしたり、
36
+ 名前空間つきの関数でシャドーイングすることはできません。
37
+ </simpara >
38
+ </caution >
31
39
</refsect1 >
32
40
33
41
<refsect1 role =" parameters" >
34
42
&reftitle.parameters;
35
- <para >
36
- <variablelist >
37
- <varlistentry >
38
- <term ><parameter >status</parameter ></term >
39
- <listitem >
40
- <para >
41
- <parameter >status</parameter > が文字列の場合は、この関数は終了直前に
42
- <parameter >status</parameter > を表示します。
43
- </para >
44
- <para >
45
- <parameter >status</parameter > が <type >int</type > の場合は
46
- その値が終了ステータスとして使われ、表示はされません。終了ステータスは
47
- 0 から 254 までの値でなければなりません。終了ステータス 255 は
48
- PHP に予約されており、使用してはいけません。ステータス 0 は、
49
- プログラムを正常終了させる際に使用します。
50
- </para >
51
- </listitem >
52
- </varlistentry >
53
- </variablelist >
54
- </para >
43
+ <variablelist >
44
+ <varlistentry >
45
+ <term ><parameter >status</parameter ></term >
46
+ <listitem >
47
+ <simpara >
48
+ <parameter >status</parameter > が文字列の場合は、
49
+ この関数は終了直前に <parameter >status</parameter > を表示します。
50
+ PHP によって返される終了コードは <literal >0</literal > です。
51
+ </simpara >
52
+ <para >
53
+ <parameter >status</parameter > が <type >int</type > の場合は、
54
+ この関数は終了直前に <parameter >status</parameter > を表示します。
55
+ <note >
56
+ <simpara >
57
+ 終了コードは <literal >0</literal > から <literal >254</literal > の範囲でなければならず、
58
+ 終了コード <literal >255</literal > は PHP によって予約されているため使用できません。
59
+ </simpara >
60
+ </note >
61
+ </para >
62
+ <warning >
63
+ <simpara >
64
+ PHP 8.4.0 より前のバージョンでは、 <function >exit</function > は PHP の標準的な
65
+ <link linkend =" language.types.type-juggling.function" >型の相互変換のセマンティクス</link >に基づいておらず、
66
+ また、<link linkend =" language.types.declarations.strict" ><literal >strict_types</literal ></link > 宣言も適用されませんでした。
67
+ </simpara >
68
+ <simpara >
69
+ また、<type >resource</type > や <type >array</type > を含む、<type >int</type > 型以外の値は
70
+ <type >string</type > にキャストされていました。
71
+ PHP 8.4.0 以降は、通常の型の相互変換が適用され、無効な値に対しては
72
+ <exceptionname >TypeError</exceptionname > をスローします。
73
+ </simpara >
74
+ </warning >
75
+ </listitem >
76
+ </varlistentry >
77
+ </variablelist >
55
78
</refsect1 >
56
79
57
80
<refsect1 role =" returnvalues" >
58
81
&reftitle.returnvalues;
59
- <para >
60
- &return.void;
61
- </para >
82
+ <simpara >
83
+ この関数は PHP スクリプトを終了するため、値を返すことはありません。
84
+ </simpara >
85
+ </refsect1 >
86
+
87
+ <refsect1 role =" changelog" >
88
+ &reftitle.changelog;
89
+ <informaltable >
90
+ <tgroup cols =" 2" >
91
+ <thead >
92
+ <row >
93
+ <entry >&Version; </entry >
94
+ <entry >&Description; </entry >
95
+ </row >
96
+ </thead >
97
+ <tbody >
98
+ <row >
99
+ <entry >8.4.0</entry >
100
+ <entry >
101
+ <function >exit</function > は言語構造から正式な関数になったので、
102
+ 通常の
103
+ <link linkend =" language.types.type-juggling.function" >型の相互変換</link >
104
+ に従い、
105
+ <link linkend =" language.types.declarations.strict" ><literal >strict_types</literal ></link >
106
+ 宣言も適用されるようになりました。また、名前付き引数や
107
+ <link linkend =" functions.variable-functions" >可変関数</link >
108
+ によって呼び出すこともできるようになりました。
109
+ </entry >
110
+ </row >
111
+ </tbody >
112
+ </tgroup >
113
+ </informaltable >
62
114
</refsect1 >
63
115
64
116
<refsect1 role =" examples" >
65
117
&reftitle.examples;
66
- <para >
67
- <example >
68
- <title ><literal >exit</literal > の例</title >
69
- <programlisting role =" php" >
118
+ <example >
119
+ <title ><function >exit</function > の基本的な使用例</title >
120
+ <programlisting role =" php" >
70
121
<![CDATA[
71
122
<?php
72
123
73
- $filename = '/path/to/data-file';
74
- $file = fopen($filename, 'r')
75
- or exit("ファイル ($filename) をオープンできません");
124
+ // exit program normally
125
+ exit();
126
+ exit(0);
127
+
128
+ // exit with an error code
129
+ exit(1);
76
130
77
131
?>
78
132
]]>
79
- </programlisting >
80
- </example >
81
- </para >
82
- <para >
83
- <example >
84
- <title ><literal >exit</literal > でステータスを指定する例</title >
85
- <programlisting role =" php" >
133
+ </programlisting >
134
+ </example >
135
+ <example >
136
+ <title ><function >exit</function > に<type >string</type >を渡す例</title >
137
+ <programlisting role =" php" >
86
138
<![CDATA[
87
139
<?php
88
140
89
- // 正常終了
90
- exit;
91
- exit();
92
- exit(0);
93
-
94
- // エラーコードつきの終了
95
- exit(1);
96
- exit(0376); // 八進数
141
+ $filename = '/path/to/data-file';
142
+ $file = fopen($filename, 'r')
143
+ or exit("unable to open file ($filename)");
97
144
98
145
?>
99
146
]]>
100
- </programlisting >
101
- </example >
102
- </para >
103
- <para >
104
- <example >
105
- <title >シャットダウン関数やデストラクタが実行される例</title >
106
- <programlisting role =" php" >
147
+ </programlisting >
148
+ </example >
149
+ <example >
150
+ <title >シャットダウン関数やデストラクタが実行される例</title >
151
+ <programlisting role =" php" >
107
152
<![CDATA[
108
153
<?php
109
154
class Foo
@@ -126,41 +171,50 @@ exit();
126
171
echo 'これは出力されません。';
127
172
?>
128
173
]]>
129
- </programlisting >
130
- &example.outputs;
131
- <screen >
132
- <![CDATA[
133
- Shutdown: shutdown()
134
- Destruct: Foo::__destruct()
135
- ]]>
136
- </screen >
137
- </example >
138
- </para >
174
+ </programlisting >
175
+ &example.outputs;
176
+ <screen >
177
+ <![CDATA[
178
+ Shutdown: shutdown()
179
+ Destruct: Foo::__destruct()
180
+ ]]>
181
+ </screen >
182
+ </example >
183
+ <example >
184
+ <title >文としての <function >exit</function ></title >
185
+ <programlisting role =" php" >
186
+ <![CDATA[
187
+ <?php
188
+
189
+ // exit program normally with exit code 0
190
+ exit;
191
+
192
+ ?>
193
+ ]]>
194
+ </programlisting >
195
+ </example >
139
196
</refsect1 >
140
197
141
198
<refsect1 role =" notes" >
142
199
&reftitle.notes;
143
-
144
- ¬e.language-construct;
145
-
146
- <note >
147
- <para >
148
- この言語構造は、<function >die</function > と等価です。
149
- </para >
150
- </note >
200
+ <warning >
201
+ <simpara >
202
+ PHP 8.4.0 以降は、 <function >exit</function > は関数ではなく言語構造でした。
203
+ したがって、 <link linkend =" functions.variable-functions" >可変関数</link > や <link linkend =" functions.named-arguments" >名前付き引数</link > を使って関数を呼び出すことはできませんでした。
204
+ </simpara >
205
+ </warning >
151
206
</refsect1 >
152
207
153
208
<refsect1 role =" seealso" >
154
209
&reftitle.seealso;
155
- <para >
156
- <simplelist >
157
- <member ><function >register_shutdown_function</ function ></member >
158
- </ simplelist >
159
- </para >
210
+ <simplelist >
211
+ <member >< function >register_shutdown_function</ function ></ member >
212
+ <member ><link linkend = " function.register-shutdown-function " >シャットダウン関数</ link ></member >
213
+ <member >< link linkend = " language.oop5.decon.destructor " >オブジェクトのデストラクタ</ link ></ member >
214
+ </simplelist >
160
215
</refsect1 >
161
216
162
217
</refentry >
163
-
164
218
<!-- Keep this comment at the end of the file
165
219
Local variables:
166
220
mode: sgml
0 commit comments