diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index e4ae4450b534f..6941a433387a5 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1253,6 +1253,9 @@ ZEND_API zend_function *zend_get_call_trampoline_func(zend_class_entry *ce, zend ZEND_MAP_PTR_INIT(func->run_time_cache, (void***)&dummy); func->scope = fbc->common.scope; /* reserve space for arguments, local and temporary variables */ + /* last_var is overwritten by zend_ffi_cdata_get_closure() (overlapping + * internal function data) so we need to reset it */ + func->last_var = 0; func->T = (fbc->type == ZEND_USER_FUNCTION)? MAX(fbc->op_array.last_var + fbc->op_array.T, 2) : 2; func->filename = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.filename : ZSTR_EMPTY_ALLOC(); func->line_start = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.line_start : 0; diff --git a/ext/ffi/tests/trampoline_reset.phpt b/ext/ffi/tests/trampoline_reset.phpt new file mode 100644 index 0000000000000..47320d53753ac --- /dev/null +++ b/ext/ffi/tests/trampoline_reset.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test +--EXTENSIONS-- +ffi +--SKIPIF-- + +--INI-- +ffi.enable=1 +--FILE-- +fprintf($ffi->stdout, "FFI\n"); +$ffi->fflush($ffi->stdout); +Test::baz(); +?> +--EXPECT-- +foo called +bar called +FFI +baz called