Skip to content

Don’t reset func in zend_closure_internal_handler #9849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,6 @@ static ZEND_NAMED_FUNCTION(zend_closure_internal_handler) /* {{{ */
zend_closure *closure = (zend_closure*)ZEND_CLOSURE_OBJECT(EX(func));
closure->orig_internal_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
OBJ_RELEASE((zend_object*)closure);
EX(func) = NULL;
}
/* }}} */

Expand Down
2 changes: 2 additions & 0 deletions Zend/zend_observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ ZEND_API bool zend_observer_remove_end_handler(zend_function *function, zend_obs

static inline zend_execute_data **prev_observed_frame(zend_execute_data *execute_data) {
zend_function *func = EX(func);
ZEND_ASSERT(func);
return (zend_execute_data **)&Z_PTR_P(EX_VAR_NUM((ZEND_USER_CODE(func->type) ? func->op_array.last_var : ZEND_CALL_NUM_ARGS(execute_data)) + func->common.T - 1));
}

Expand Down Expand Up @@ -260,6 +261,7 @@ ZEND_API void ZEND_FASTCALL zend_observer_fcall_begin(zend_execute_data *execute

static inline void call_end_observers(zend_execute_data *execute_data, zval *return_value) {
zend_function *func = execute_data->func;
ZEND_ASSERT(func);

zend_observer_fcall_end_handler *handler = (zend_observer_fcall_end_handler *)&ZEND_OBSERVER_DATA(func) + zend_observers_fcall_list.count;
// TODO: Fix exceptions from generators
Expand Down
26 changes: 26 additions & 0 deletions ext/zend_test/tests/observer_closure_03.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
Observer: Observability of closures of builtin functions
--EXTENSIONS--
zend_test
--INI--
zend_test.observer.enabled=1
zend_test.observer.observe_all=1
--FILE--
<?php
$closure = strlen(...);
var_dump($closure('test'));

echo 'DONE' . PHP_EOL;
?>
--EXPECTF--
<!-- init '%s' -->
<file '%s'>
<!-- init strlen() -->
<strlen>
</strlen>
<!-- init var_dump() -->
<var_dump>
int(4)
</var_dump>
DONE
</file '%s'>