Skip to content

Commit 21a9ad9

Browse files
committed
Fixed bug #79548
When duplicating user functions with static variables, make sure that we init a new map ptr slot for the static variables.
1 parent 733d84d commit 21a9ad9

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

Zend/zend_inheritance.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,14 @@ static zend_function *zend_duplicate_user_function(zend_function *func) /* {{{ *
8686
if (!(GC_FLAGS(new_function->op_array.static_variables) & IS_ARRAY_IMMUTABLE)) {
8787
GC_ADDREF(new_function->op_array.static_variables);
8888
}
89-
ZEND_MAP_PTR_INIT(new_function->op_array.static_variables_ptr, &new_function->op_array.static_variables);
89+
90+
if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) {
91+
ZEND_ASSERT(new_function->op_array.fn_flags & ZEND_ACC_PRELOADED);
92+
ZEND_MAP_PTR_NEW(new_function->op_array.static_variables_ptr);
93+
} else {
94+
ZEND_MAP_PTR_INIT(new_function->op_array.static_variables_ptr, &new_function->op_array.static_variables);
95+
}
96+
9097
return new_function;
9198
}
9299
/* }}} */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
class A {
4+
public function test() {
5+
static $foo;
6+
}
7+
}
8+
9+
class B extends A {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #79548: Preloading segfault with inherited method using static variable
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload={PWD}/preload_static_var_inheritance.inc
8+
--SKIPIF--
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
13+
--FILE--
14+
<?php
15+
var_dump((new B)->test());
16+
?>
17+
--EXPECT--
18+
NULL

0 commit comments

Comments
 (0)