Exceptions thrown during yield operation fall through the generator instead of being handled within
未关闭
还没有人认领这个 Issue。
Bug
Category: Engine
Status: Verified
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
The following code:
<?php
set_error_handler(function() { throw new \Error(); });
function &gen() {
try {
yield 1;
} catch (Error $e) {
print "Caught";
}
}
foreach (gen() as $y);
Resulted in Uncaught Error
But I expected this output instead:
Caught
return_by_ref has the same problem, it seems to me, however in generators there's the additional case of exceptions in destructors of previous key and values.
I wouldn't change the longstanding behaviour in current PHP versions, but should be fixed for PHP 8.2 possibly, for academical correctness at least.
PHP Version
master
Operating System
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
在 PHP master 上复现提供的 generator 示例,并将观察到的错误流与预期的 catch 行为进行比较。然后检查 generator 的 yield 处理、按引用返回的行为以及所提到的 destructor 情况。对于报告的场景,预期的异常处理已得到定义并覆盖,且未无意中更改既有行为,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- php
- 领域
- compilers
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100