Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69bcbdc

Browse files
Fix handling of nested generator in zend_test observer
This is the counterpart of GH-15952. Fixes GH-16514 Closes GH-16530
1 parent 8720063 commit 69bcbdc

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

‎ext/zend_test/observer.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "zend_observer.h"
2121
#include "zend_smart_str.h"
2222
#include "ext/standard/php_var.h"
23+
#include "zend_generators.h"
2324

2425
static zend_observer_fcall_handlers observer_fcall_init(zend_execute_data *execute_data);
2526

@@ -163,6 +164,11 @@ static void observer_show_init_backtrace(zend_execute_data *execute_data)
163164
zend_execute_data *ex = execute_data;
164165
php_printf("%*s<!--\n", 2 * ZT_G(observer_nesting_depth), "");
165166
do {
167+
if (UNEXPECTED(!ex->func)) {
168+
ex = zend_generator_check_placeholder_frame(ex);
169+
ZEND_ASSERT(ex->func);
170+
}
171+
166172
zend_function *fbc = ex->func;
167173
int indent = 2 * ZT_G(observer_nesting_depth) + 4;
168174
if (fbc->common.function_name) {

‎ext/zend_test/tests/gh16514.phpt‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
GH-16514: Nested generator in zend_test observer
3+
--EXTENSIONS--
4+
zend_test
5+
--INI--
6+
zend_test.observer.enabled=1
7+
zend_test.observer.show_init_backtrace=1
8+
--FILE--
9+
<?php
10+
11+
class Foo {
12+
public function __destruct() {
13+
debug_print_backtrace();
14+
}
15+
}
16+
function bar() {
17+
yield from foo();
18+
}
19+
function foo() {
20+
$foo = new Foo();
21+
yield;
22+
}
23+
$gen = bar();
24+
foreach ($gen as $dummy);
25+
26+
?>
27+
--EXPECTF--
28+
<!-- init '%sgh16514.php' -->
29+
<!--
30+
{main} %sgh16514.php
31+
-->
32+
<!-- init bar() -->
33+
<!--
34+
bar()
35+
{main} %sgh16514.php
36+
-->
37+
<!-- init foo() -->
38+
<!--
39+
foo()
40+
bar()
41+
{main} %sgh16514.php
42+
-->
43+
<!-- init Foo::__destruct() -->
44+
<!--
45+
Foo::__destruct()
46+
bar()
47+
{main} %sgh16514.php
48+
-->
49+
<!-- init debug_print_backtrace() -->
50+
<!--
51+
debug_print_backtrace()
52+
Foo::__destruct()
53+
bar()
54+
{main} %sgh16514.php
55+
-->
56+
#0 %s(%d): Foo->__destruct()
57+
#1 %s(%d): bar()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /