php / php/php-src

set_exception_handler not restored if calling exit within itself

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

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

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

説明

Description

What was fixed https://github.com/php/php-src/commit/3301d9602a2307007858c299c41795d3d95e3843 https://github.com/php/php-src/issues/13446#issuecomment-1991549384 bc it was broken from 8.3.0-8.3.4 is still broken if the exception handler itself calls exit.

https://3v4l.org/HkWfh
without exit: https://3v4l.org/FTWQf

The following code:

<?php

declare(strict_types=1);

function foo($e) {
    var_dump( set_exception_handler('foo') );
    restore_exception_handler();
    echo "---" . PHP_EOL;
    exit;
}

set_exception_handler('foo');

register_shutdown_function(function () {
    var_dump( set_exception_handler(null) );
});

strlen(null);

Resulted in this output:

NULL
---
NULL

But I expected this output instead:

NULL
---
string(3) "foo"

This matters, because since PHP 8.3, the exit code of the exit() call in exception handler is used as exit code of PHP

@iluuu1994

PHP Version
PHP 8.3.0+
Operating System

No response

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

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

はじめの一歩

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

調査の方向性

まず、提供された PHP スクリプトで動作を再現し、リンクされている 3v4l の例の exit ケースと非 exit ケースを比較します。PHP ランタイムにおける set_exception_handler()、restore_exception_handler()、register_shutdown_function()、exit の相互作用を追跡します。exception handler 内で exit が呼び出されたときに、shutdown callback が復元された "foo" handler を確認できれば完了です。

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

評価

技術スタック
c, php
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

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

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