diff --git a/Zend/tests/partial_application/default_const_expr_shm.phpt b/Zend/tests/partial_application/default_const_expr_shm.phpt new file mode 100644 index 000000000000..d3ac8900094a --- /dev/null +++ b/Zend/tests/partial_application/default_const_expr_shm.phpt @@ -0,0 +1,25 @@ +--TEST-- +PFA: default value AST of an SHM-persisted partial +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.file_update_protection=0 +--FILE-- +getParameters()[2]; +var_dump($param->getDefaultValue()); + +?> +--EXPECT-- +array(1) { + ["a"]=> + string(1) "1" +} +int(0) diff --git a/Zend/zend_partial.c b/Zend/zend_partial.c index a4cc4a4ce571..497e9b80d576 100644 --- a/Zend/zend_partial.c +++ b/Zend/zend_partial.c @@ -1011,11 +1011,10 @@ static zend_op_array *zp_compile(zval *this_ptr, zend_function *function, } #endif + /* Takes ownership of closure_ast */ op_array = zend_accel_compile_pfa(closure_ast, declaring_filename, declaring_lineno_ptr, function, pfa_name, flags & ZEND_PARTIAL_CACHEABLE_IN_SHM); - zend_ast_destroy(closure_ast); - clean: zp_names_dtor(var_names, argc); zend_arena_destroy(CG(ast_arena)); diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index 05fb6700ea72..bb4a1fbb5cf2 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -2121,6 +2121,8 @@ zend_op_array *zend_accel_compile_pfa(zend_ast *ast, zend_bailout(); } zend_end_try(); + zend_ast_destroy(ast); + ZEND_ASSERT(op_array->num_dynamic_func_defs == 1); zend_string_release(op_array->dynamic_func_defs[0]->function_name); diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h index fe83800f3a06..79208893d12f 100644 --- a/ext/opcache/ZendAccelerator.h +++ b/ext/opcache/ZendAccelerator.h @@ -340,6 +340,7 @@ uint32_t zend_accel_get_class_name_map_ptr(zend_string *type_name); const zend_op_array *zend_accel_pfa_cache_get( const uint32_t *declaring_lineno_ptr, const zend_function *called_function, bool cacheable_in_shm); +/* Compiles ast into an op_array, and caches it. Takes ownership of ast. */ zend_op_array *zend_accel_compile_pfa(zend_ast *ast, zend_string *declaring_filename, const uint32_t *declaring_lineno_ptr,