Skip to content

Commit ebc8e3b

Browse files
committed
Don't use separate static variables in inherited methods
1 parent 709e45d commit ebc8e3b

File tree

6 files changed

+20
-31
lines changed

6 files changed

+20
-31
lines changed

Zend/tests/anon/015.phpt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ var_dump($d->foo(24));
1919
var_dump($c->foo());
2020
?>
2121
--EXPECT--
22-
NULL
22+
array(1) {
23+
[0]=>
24+
int(42)
25+
}
2326
array(1) {
2427
[0]=>
2528
int(24)
2629
}
2730
array(1) {
2831
[0]=>
29-
int(42)
32+
int(24)
3033
}

Zend/tests/anon/016.phpt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ var_dump($d->foo(24));
1919
var_dump($c->foo());
2020
?>
2121
--EXPECT--
22-
NULL
22+
array(1) {
23+
[0]=>
24+
object(stdClass)#2 (0) {
25+
}
26+
}
2327
array(1) {
2428
[0]=>
2529
int(24)
2630
}
2731
array(1) {
2832
[0]=>
29-
object(stdClass)#2 (0) {
30-
}
33+
int(24)
3134
}

Zend/tests/method_static_var.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ Bar::test();
2020
--EXPECT--
2121
int(1)
2222
int(2)
23-
int(1)
24-
int(2)
23+
int(3)
24+
int(4)

Zend/zend_inheritance.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,7 @@ static zend_function *zend_duplicate_internal_function(zend_function *func, zend
8787
}
8888
/* }}} */
8989

90-
static zend_function *zend_duplicate_user_function(zend_function *func) /* {{{ */
91-
{
92-
zend_op_array *new_op_array = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
93-
memcpy(new_op_array, func, sizeof(zend_op_array));
94-
zend_init_static_variables_map_ptr(new_op_array);
95-
return (zend_function *) new_op_array;
96-
}
97-
/* }}} */
98-
99-
static zend_always_inline zend_function *zend_duplicate_function(zend_function *func, zend_class_entry *ce, bool is_interface) /* {{{ */
90+
static zend_always_inline zend_function *zend_duplicate_function(zend_function *func, zend_class_entry *ce) /* {{{ */
10091
{
10192
if (UNEXPECTED(func->type == ZEND_INTERNAL_FUNCTION)) {
10293
return zend_duplicate_internal_function(func, ce);
@@ -107,12 +98,7 @@ static zend_always_inline zend_function *zend_duplicate_function(zend_function *
10798
if (EXPECTED(func->op_array.function_name)) {
10899
zend_string_addref(func->op_array.function_name);
109100
}
110-
if (is_interface
111-
|| EXPECTED(!func->op_array.static_variables)) {
112-
/* reuse the same op_array structure */
113-
return func;
114-
}
115-
return zend_duplicate_user_function(func);
101+
return func;
116102
}
117103
}
118104
/* }}} */
@@ -937,9 +923,7 @@ static zend_always_inline inheritance_status do_inheritance_check_on_method_ex(
937923

938924
if (!check_only && child->common.prototype != proto && child_zv) {
939925
do {
940-
if (child->common.scope != ce
941-
&& child->type == ZEND_USER_FUNCTION
942-
&& !child->op_array.static_variables) {
926+
if (child->common.scope != ce && child->type == ZEND_USER_FUNCTION) {
943927
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
944928
/* Few parent interfaces contain the same method */
945929
break;
@@ -1010,7 +994,7 @@ static zend_always_inline void do_inherit_method(zend_string *key, zend_function
1010994
ce->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
1011995
}
1012996

1013-
parent = zend_duplicate_function(parent, ce, is_interface);
997+
parent = zend_duplicate_function(parent, ce);
1014998

1015999
if (!is_interface) {
10161000
_zend_hash_append_ptr(&ce->function_table, key, parent);

ext/opcache/tests/preload_method_static_vars.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ Bar::test();
1818
--EXPECT--
1919
int(1)
2020
int(2)
21-
int(1)
22-
int(2)
21+
int(3)
22+
int(4)
2323

2424
int(1)
25-
int(1)
25+
int(2)

ext/opcache/zend_persist.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,6 @@ static void zend_persist_class_method(zval *zv, zend_class_entry *ce)
736736
}
737737

738738
if ((op_array->fn_flags & ZEND_ACC_IMMUTABLE)
739-
&& !op_array->static_variables
740739
&& !ZCG(current_persistent_script)->corrupted
741740
&& zend_accel_in_shm(op_array)) {
742741
zend_shared_alloc_register_xlat_entry(op_array, op_array);

0 commit comments

Comments
 (0)