php / php/php-src

evade `exit_status` overwrite by `exit()`

オープン
#15,796 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Category: Engine Feature Status: Verified
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

as you know there could be multiple exit() occurrences with the help of register_shutdown_function

my case exactly is a shutdown handler that executes once and does exit(), but original exit_status is lost because exit overwrites it. i would like to keep the original exit code. here's some code sample for quick showcase:

register_shutdown_function(function() {
  done(true);# bad termination
});
work();
done();# good termination
###
function work(): void
{
  throw new \Exception('test');# same as exit(255);
  #exit(1001);
}
function done(bool $bad=false): void
{
  static $DID=0;
  if ($DID) {
    return;
  }
  $DID++;
  # ...
  # cleanup
  # ...
  exit($bad ? 1 : 0);
  #exit(exit_status() ?: ($bad ? 1 : 0));# this may save the original
}

to keep behavior the same, i propose to add exit_status() getter similar to error_reporting() that only gets a exit_status value. what you think?

to test those, ive added it right after error_reporting
https://github.com/php/php-src/blob/e358634cdce6a7505b7d422c23ec205a483ad2fc/Zend/zend_builtin_functions.c#L457

ZEND_FUNCTION(exit_status) // {{{
{
	RETURN_LONG(EG(exit_status));
}
// }}}

but also have to add these in https://github.com/php/php-src/blob/master/Zend/zend_builtin_functions_arginfo.h

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_exit_status, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
// ...
ZEND_FUNCTION(exit_status);
// ...
	ZEND_FE(exit_status, arginfo_exit_status)

it has some php file (https://github.com/php/php-src/blob/master/Zend/zend_builtin_functions.stub.php) to generate, i didnt get how to use it

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Zend/zend_builtin_functions.c と既存の error_reporting エントリポイントから始め、次に Zend/zend_builtin_functions.stub.php と生成された Zend/zend_builtin_functions_arginfo.h を調べます。新しい exit_status builtin の生成およびテストでサポートされているワークフローを特定します。提案が解決され、既存の終了動作を変更せずに元の終了ステータスを取得できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
c, php
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
28/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。