Skip to content

Commit d567688

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #78950: Preloading trait method with static variables
2 parents cf93621 + be89a5c commit d567688

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

Zend/zend_compile.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,9 +1041,16 @@ ZEND_API void function_add_ref(zend_function *function) /* {{{ */
10411041
&& !(GC_FLAGS(op_array->static_variables) & IS_ARRAY_IMMUTABLE)) {
10421042
GC_ADDREF(op_array->static_variables);
10431043
}
1044-
ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, &op_array->static_variables);
1045-
ZEND_MAP_PTR_INIT(op_array->run_time_cache, zend_arena_alloc(&CG(arena), sizeof(void*)));
1046-
ZEND_MAP_PTR_SET(op_array->run_time_cache, NULL);
1044+
1045+
if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) {
1046+
ZEND_ASSERT(op_array->fn_flags & ZEND_ACC_PRELOADED);
1047+
ZEND_MAP_PTR_NEW(op_array->run_time_cache);
1048+
ZEND_MAP_PTR_NEW(op_array->static_variables_ptr);
1049+
} else {
1050+
ZEND_MAP_PTR_INIT(op_array->static_variables_ptr, &op_array->static_variables);
1051+
ZEND_MAP_PTR_INIT(op_array->run_time_cache, zend_arena_alloc(&CG(arena), sizeof(void*)));
1052+
ZEND_MAP_PTR_SET(op_array->run_time_cache, NULL);
1053+
}
10471054
} else if (function->type == ZEND_INTERNAL_FUNCTION) {
10481055
if (function->common.function_name) {
10491056
zend_string_addref(function->common.function_name);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
trait Foo {
4+
public function test() {
5+
static $bar;
6+
var_dump($bar);
7+
}
8+
}
9+
10+
class Bar {
11+
use Foo;
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Preload trait with static variables in method
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload={PWD}/preload_trait_static.inc
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
$bar = new Bar;
13+
$bar->test();
14+
?>
15+
--EXPECT--
16+
NULL

0 commit comments

Comments
 (0)