diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-17 10:47:30 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-18 11:18:19 +0100 |
commit | 5d160e309ed207e618d49029e51c9c2dc2c5e61c (patch) | |
tree | a6f1deb6f582e42792a8dccedb117a26decd3e65 /Zend/zend_compile.c | |
parent | e03284739f4a3a1052dfe5497fbf06c1b206f895 (diff) | |
download | php-git-5d160e309ed207e618d49029e51c9c2dc2c5e61c.tar.gz |
Fix static variable behavior with inheritance
When a method is inherited, the static variables will now always
use the initial values, rather than the values at the time of
inheritance. As such, behavior no longer depends on whether
inheritance happens before or after a method has been called.
This is implemented by always keeping static_variables as the
original values, and static_variables_ptr as the modified copy.
Closes GH-6705.
Diffstat (limited to 'Zend/zend_compile.c')
-rw-r--r-- | Zend/zend_compile.c | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 5d566b43a5..d76b8f74ec 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -1029,28 +1029,32 @@ static uint32_t zend_add_try_element(uint32_t try_op) /* {{{ */ } /* }}} */ +void zend_init_static_variables_map_ptr(zend_op_array *op_array) +{ + if (op_array->static_variables) { + ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, + zend_arena_alloc(&CG(arena), sizeof(HashTable *))); + ZEND_MAP_PTR_SET(op_array->static_variables_ptr, NULL); + } +} + ZEND_API void function_add_ref(zend_function *function) /* {{{ */ { if (function->type == ZEND_USER_FUNCTION) { zend_op_array *op_array = &function->op_array; - if (op_array->refcount) { (*op_array->refcount)++; } - if (op_array->static_variables - && !(GC_FLAGS(op_array->static_variables) & IS_ARRAY_IMMUTABLE)) { - GC_ADDREF(op_array->static_variables); - } if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) { ZEND_ASSERT(op_array->fn_flags & ZEND_ACC_PRELOADED); ZEND_MAP_PTR_NEW(op_array->run_time_cache); - ZEND_MAP_PTR_NEW(op_array->static_variables_ptr); } else { - ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, &op_array->static_variables); - ZEND_MAP_PTR_INIT(op_array->run_time_cache, zend_arena_alloc(&CG(arena), sizeof(void*))); + ZEND_MAP_PTR_INIT(op_array->run_time_cache, zend_arena_alloc(&CG(arena), sizeof(void *))); ZEND_MAP_PTR_SET(op_array->run_time_cache, NULL); } + + zend_init_static_variables_map_ptr(op_array); } if (function->common.function_name) { @@ -7021,9 +7025,8 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel) /* {{{ if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) { op_array->fn_flags |= ZEND_ACC_PRELOADED; ZEND_MAP_PTR_NEW(op_array->run_time_cache); - ZEND_MAP_PTR_NEW(op_array->static_variables_ptr); } else { - ZEND_MAP_PTR_INIT(op_array->run_time_cache, zend_arena_alloc(&CG(arena), sizeof(void*))); + ZEND_MAP_PTR_INIT(op_array->run_time_cache, zend_arena_alloc(&CG(arena), sizeof(void *))); ZEND_MAP_PTR_SET(op_array->run_time_cache, NULL); } @@ -7112,6 +7115,7 @@ void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel) /* {{{ zend_do_extended_stmt(); zend_emit_final_return(0); + zend_init_static_variables_map_ptr(op_array); pass_two(CG(active_op_array)); zend_oparray_context_end(&orig_oparray_context); |