如果您想避免在 FastCGI 中呼叫 exit(),如以下註釋所述,但又真的、確實想要從巢狀函式呼叫或 include 中乾淨地退出,請考慮使用 Python 的方式
定義一個名為 `SystemExit` 的例外,在呼叫 exit() 時拋出它,並在 index.php 中使用一個空的處理程式來攔截它,以乾淨地結束腳本執行。
<?php
// 檔案:index.php
class SystemExit extends Exception {}
try {
/* 程式碼 程式碼 */
}
catch (SystemExit $e) { /* 什麼都不做 */ }
// 檔案結尾:index.php
// 一些深度巢狀的函式或 .php 檔案
if (SOME_EXIT_CONDITION)
throw new SystemExit(); // 取代 exit()
?>