Skip to content

[PHP8.4] die,exitの翻訳 #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions reference/misc/functions/die.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
<refentry xml:id="function.die" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>die</refname>
<refpurpose><literal>exit</literal> と同等</refpurpose>
<refpurpose><function>exit</function> &Alias;</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<para>
この言語構造は、<function>exit</function> と同等です。
</para>
<simpara>
<function>exit</function>
&info.function.alias;
</simpara>
</refsect1>

</refentry>
Expand Down
228 changes: 141 additions & 87 deletions reference/misc/functions/exit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,105 +5,151 @@
<refentry xml:id="function.exit" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>exit</refname>
<refpurpose>メッセージを出力し、現在のスクリプトを終了する</refpurpose>
<refpurpose>ステータスコードかメッセージを返して現在のスクリプトを終了する</refpurpose>
</refnamediv>

<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>void</type><methodname>exit</methodname>
<methodparam choice="opt"><type>string</type><parameter>status</parameter></methodparam>
<type>never</type><methodname>exit</methodname>

<type>never</type><methodname>exit</methodname>
<methodparam choice="opt"><type class="union"><type>string</type><type>int</type></type><parameter>status</parameter><initializer>0</initializer></methodparam>
</methodsynopsis>
<methodsynopsis>
<type>void</type><methodname>exit</methodname>
<methodparam><type>int</type><parameter>status</parameter></methodparam>
</methodsynopsis>
<para>
<simpara>
スクリプトの実行を終了します。
<link linkend="function.register-shutdown-function">シャットダウン関数</link>
や <link linkend="language.oop5.decon.destructor">オブジェクトのデストラクタ</link>
は、<literal>exit</literal> がコールされた場合にも実行されます。
</para>
<para>
<literal>exit</literal> は言語構造です。
<parameter>status</parameter> を指定しない場合は括弧なしでコールできます。
</para>
は、<function>exit</function> がコールされた場合にも実行されます。
ただし、&finally; ブロックは実行されません。
</simpara>

<simpara>
終了コード '0' は、そのタスクでプログラムが成功したことを表します。
他の値は、実行中に何らかのエラーが発生したことを表します。
</simpara>
<simpara>
<function>exit</function> は特殊な関数です。
パーサーに専用のトークンがあるため、文として使用して(つまり、括弧なしで)、
デフォルトのステータスコードでスクリプトを終了させることができます。
</simpara>

<caution>
<simpara>
グローバルな <function>exit</function> を無効にしたり、
名前空間つきの関数でシャドウィングすることはできません。
</simpara>
</caution>
</refsect1>

<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>status</parameter></term>
<listitem>
<para>
<parameter>status</parameter> が文字列の場合は、この関数は終了直前に
<parameter>status</parameter> を表示します。
</para>
<para>
<parameter>status</parameter> が <type>int</type> の場合は
その値が終了ステータスとして使われ、表示はされません。終了ステータスは
0 から 254 までの値でなければなりません。終了ステータス 255 は
PHP に予約されており、使用してはいけません。ステータス 0 は、
プログラムを正常終了させる際に使用します。
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
<variablelist>
<varlistentry>
<term><parameter>status</parameter></term>
<listitem>
<simpara>
<parameter>status</parameter> が文字列の場合は、
この関数は終了直前に <parameter>status</parameter> を表示します。
PHP によって返される終了コードは <literal>0</literal> です。
</simpara>
<para>
<parameter>status</parameter> が <type>int</type> の場合は、
この関数は終了直前に <parameter>status</parameter> を表示します。
<note>
<simpara>
終了コードは <literal>0</literal> から <literal>254</literal> の範囲でなければならず、
終了コード <literal>255</literal> は PHP によって予約されているため使用できません。
</simpara>
</note>
</para>
<warning>
<simpara>
PHP 8.4.0 より前のバージョンでは、 <function>exit</function> は PHP の標準的な
<link linkend="language.types.type-juggling.function">型の相互変換</link>に基づいておらず、
また、<link linkend="language.types.declarations.strict"><literal>strict_types</literal></link> 宣言も適用されませんでした。
</simpara>
<simpara>
<type>int</type> 型以外の値が <type>resource</type> や <type>array</type> を含む <type>string</type> にキャストされていました。
PHP 8.4.0 以降は、通常の型の相互変換が適用され、無効な値に対しては
<exceptionname>TypeError</exceptionname> をスローします。
</simpara>
</warning>
</listitem>
</varlistentry>
</variablelist>
</refsect1>

<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.void;
</para>
<simpara>
この関数は PHP スクリプトを終了するため、値を返すことはありません。
</simpara>
</refsect1>

<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
<function>exit</function> は現在適切な関数であるため、
通常の
<link linkend="language.types.type-juggling.function">型の相互変換</link>
<link linkend="language.types.declarations.strict"><literal>strict_types</literal></link>
宣言によって適用され、名前付き引数を使って呼び出すことができ、また、
<link linkend="functions.variable-functions">可変関数</link> でもあります。
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>

<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title><literal>exit</literal> の例</title>
<programlisting role="php">
<example>
<title><function>exit</function> の基本的な使用例</title>
<programlisting role="php">
<![CDATA[
<?php

$filename = '/path/to/data-file';
$file = fopen($filename, 'r')
or exit("ファイル ($filename) をオープンできません");
// exit program normally
exit();
exit(0);
// exit with an error code
exit(1);

?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title><literal>exit</literal> でステータスを指定する例</title>
<programlisting role="php">
</programlisting>
</example>
<example>
<title><function>exit</function> に<type>string</type>を渡す例</title>
<programlisting role="php">
<![CDATA[
<?php

// 正常終了
exit;
exit();
exit(0);

// エラーコードつきの終了
exit(1);
exit(0376); // 八進数
$filename = '/path/to/data-file';
$file = fopen($filename, 'r')
or exit("unable to open file ($filename)");

?>
]]>
</programlisting>
</example>
</para>
<para>
<example>
<title>シャットダウン関数やデストラクタが実行される例</title>
<programlisting role="php">
</example>
<example>
<title>シャットダウン関数やデストラクタが実行される例</title>
<programlisting role="php">
<![CDATA[
<?php
class Foo
Expand All @@ -127,36 +173,44 @@ echo 'これは出力されません。';
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
Shutdown: shutdown()
Destruct: Foo::__destruct()
]]>
</screen>
</example>
</para>
&example.outputs;
<screen>
<![CDATA[
Shutdown: shutdown()
Destruct: Foo::__destruct()
]]>
</screen>
</example>
<example>
<title>文としての <function>exit</function></title>
<programlisting role="php">
<![CDATA[
<?php
// exit program normally with exit code 0
exit;
?>
]]>
</programlisting>
</example>
</refsect1>

<refsect1 role="notes">
&reftitle.notes;

&note.language-construct;

<note>
<para>
この言語構造は、<function>die</function> と等価です。
</para>
</note>
<warning>
<simpara>
PHP 8.4.0 以降は、 <function>exit</function> は関数ではなく言語構造でした。
従って、 <link linkend="functions.variable-functions">可変関数</link> や <link linkend="functions.named-arguments">名前付き引数</link> を使って関数を呼び出すことはできませんでした。
</simpara>
</warning>
</refsect1>

<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>register_shutdown_function</function></member>
</simplelist>
</para>
<simplelist>
<member><function>register_shutdown_function</function></member>
<member><link linkend="function.register-shutdown-function">シャットダウン関数</link></member>
<member><link linkend="language.oop5.decon.destructor">オブジェクトのデストラクタ</link></member>
</simplelist>
</refsect1>

</refentry>
Expand Down