Skip to content

Commit dc26668

Browse files
committed
static vars fix
1 parent 99d21d5 commit dc26668

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
Static variables in partial functions
3+
--FILE--
4+
<?php
5+
$function = function() {
6+
static $var = 0;
7+
8+
return ++$var;
9+
};
10+
11+
var_dump($function(), ($function(?))());
12+
13+
$function = function() {
14+
static $vars = [];
15+
static $ex = 0;
16+
17+
switch ($ex++) {
18+
case 0:
19+
$vars[] = "Hello";
20+
break;
21+
22+
case 1:
23+
$vars[] = "World";
24+
break;
25+
}
26+
27+
return $vars;
28+
};
29+
30+
var_dump($function(), ($function(?))());
31+
?>
32+
--EXPECT--
33+
int(1)
34+
int(2)
35+
array(1) {
36+
[0]=>
37+
string(5) "Hello"
38+
}
39+
array(2) {
40+
[0]=>
41+
string(5) "Hello"
42+
[1]=>
43+
string(5) "World"
44+
}
45+

Zend/zend_partial.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ static HashTable *zend_partial_get_gc(zend_object *obj, zval **table, int *n)
302302
*table = Z_TYPE(partial->This) == IS_OBJECT ? &partial->This : NULL;
303303
*n = Z_TYPE(partial->This) == IS_OBJECT ? 1 : 0;
304304

305-
return (partial->func.type == ZEND_USER_FUNCTION) ?
306-
ZEND_MAP_PTR_GET(partial->func.op_array.static_variables_ptr) : NULL;
305+
return NULL;
307306
}
308307

309308
static zend_function *zend_partial_get_method(zend_object **object, zend_string *method, const zval *key) /* {{{ */
@@ -567,9 +566,6 @@ void zend_partial_apply(zval *result, uint32_t info, zend_execute_data *call) {
567566

568567
if (partial->func.type == ZEND_USER_FUNCTION) {
569568
zend_op_array *ops = (zend_op_array*) &partial->func;
570-
if (ops->static_variables) {
571-
ops->static_variables = zend_array_dup(ops->static_variables);
572-
}
573569

574570
ZEND_MAP_PTR_INIT(ops->static_variables_ptr, &ops->static_variables);
575571

0 commit comments

Comments
 (0)