php / php/php-src

set_exception_handler not restored if calling exit within itself

未关闭
#18,619 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Bug Status: Needs Triage
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 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 摘要。