Web aym.pekori.to

exit

(PHP 3, PHP 4, PHP 5)

exit -- メッセージを出力し、カレントのスクリプトを終了する

説明

void exit ( [string status] )

注意: この関数は実際には関数ではなく言語構造です。

注意: PHP >= 4.2.0 ではstatusinteger の場合それを表示しません。

exit() 関数は、スクリプトの実行を終了します。 終了直前に status を出力します。

statusinteger の場合、 その値も終了ステータスとして使用されます。 終了ステータスは 0 から 254 までの間の値であるべきであり、 ステータス 255 はPHPによって予約されているので使用すべきではありません。 ステータス 0 は、プログラムを正常に終了させる際に使用します。

例 1. exit() の例

<?php

$filename
= '/path/to/data-file';
$file = fopen ($filename, 'r')
    or exit(
"unable to open file ($filename)");

?>

例 2. exit() ステータスの例

<?php

// プログラムを正常に終了する
exit;
exit();
exit(
0);

// エラーコードとともに終了する
exit(1);
exit(
0376); // 8 進数

?>

注意: 関数 die() は、exit() の エイリアスです。

register_shutdown_function() も参照ください。