Skip to content

Commit 8776c7e

Browse files
committed
Extend zend_test internal function handler to also print leave (with return info if requested) and exception state
1 parent f957571 commit 8776c7e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

Zend/tests/attributes/nodiscard/007.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ zend_test_nodiscard();
1212
?>
1313
--EXPECTF--
1414
<!-- internal enter NoDiscard::__construct() -->
15+
<!-- internal leave NoDiscard::__construct() -->
1516

1617
Warning: The return value of function zend_test_nodiscard() should either be used or intentionally ignored by casting it as (void), custom message in %s on line %d
1718
<!-- internal enter zend_test_nodiscard() -->
19+
<!-- internal leave zend_test_nodiscard() -->

ext/zend_test/observer.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,21 @@ static void zend_test_execute_internal(zend_execute_data *execute_data, zval *re
303303
} else {
304304
fbc->internal_function.handler(execute_data, return_value);
305305
}
306+
307+
if (fbc->common.function_name) {
308+
if (EG(exception)) {
309+
php_printf("%*s<!-- Exception: %s -->\n", 2 * ZT_G(observer_nesting_depth), "", ZSTR_VAL(EG(exception)->ce->name));
310+
}
311+
312+
smart_str retval_info = {0};
313+
get_retval_info(return_value, &retval_info);
314+
if (fbc->common.scope) {
315+
php_printf("%*s<!-- internal leave %s::%s()%s -->\n", 2 * ZT_G(observer_nesting_depth), "", ZSTR_VAL(fbc->common.scope->name), ZSTR_VAL(fbc->common.function_name), retval_info.s ? ZSTR_VAL(retval_info.s) : "");
316+
} else {
317+
php_printf("%*s<!-- internal leave %s()%s -->\n", 2 * ZT_G(observer_nesting_depth), "", ZSTR_VAL(fbc->common.function_name), retval_info.s ? ZSTR_VAL(retval_info.s) : "");
318+
}
319+
smart_str_free(&retval_info);
320+
}
306321
}
307322

308323
static ZEND_INI_MH(zend_test_observer_OnUpdateCommaList)

ext/zend_test/tests/execute_internal.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Test zend_execute_internal being called
44
zend_test
55
--INI--
66
zend_test.observer.execute_internal=1
7+
zend_test.observer.show_return_value=1
78
--FILE--
89
<?php
910

@@ -14,8 +15,11 @@ function f($a) {
1415
f(time() > 0 ? [1, 2, 3] : []);
1516

1617
?>
17-
--EXPECT--
18+
--EXPECTF--
1819
<!-- internal enter time() -->
20+
<!-- internal leave time():%d -->
1921
<!-- internal enter array_sum() -->
22+
<!-- internal leave array_sum():6 -->
2023
<!-- internal enter var_dump() -->
2124
int(6)
25+
<!-- internal leave var_dump():NULL -->

0 commit comments

Comments
 (0)