When duplicating user functions with static variables, make sure
that we init a new map ptr slot for the static variables.
if (!(GC_FLAGS(new_function->op_array.static_variables) & IS_ARRAY_IMMUTABLE)) {
GC_ADDREF(new_function->op_array.static_variables);
}
- ZEND_MAP_PTR_INIT(new_function->op_array.static_variables_ptr, &new_function->op_array.static_variables);
+
+ if (CG(compiler_options) & ZEND_COMPILE_PRELOAD) {
+ ZEND_ASSERT(new_function->op_array.fn_flags & ZEND_ACC_PRELOADED);
+ ZEND_MAP_PTR_NEW(new_function->op_array.static_variables_ptr);
+ } else {
+ ZEND_MAP_PTR_INIT(new_function->op_array.static_variables_ptr, &new_function->op_array.static_variables);
+ }
+
return new_function;
}
/* }}} */
--- /dev/null
+<?php
+
+class A {
+ public function test() {
+ static $foo;
+ }
+}
+
+class B extends A {}
--- /dev/null
+--TEST--
+Bug #79548: Preloading segfault with inherited method using static variable
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.preload={PWD}/preload_static_var_inheritance.inc
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
+?>
+--FILE--
+<?php
+var_dump((new B)->test());
+?>
+--EXPECT--
+NULL