8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 398e73a commit f54c7ceCopy full SHA for f54c7ce
Zend/tests/closures/closure_const_expr/static_variable.phpt
@@ -0,0 +1,77 @@
1
+--TEST--
2
+Closures in const expressions support static variables.
3
+--FILE--
4
+<?php
5
+
6
+const Closure = static function () {
7
+ static $x = [];
8
+ static $i = 1;
9
+ $i *= 2;
10
+ $x[] = $i;
11
+ var_dump($x);
12
+};
13
14
+var_dump(Closure);
15
+(Closure)();
16
17
18
19
20
+?>
21
+--EXPECTF--
22
+object(Closure)#%d (4) {
23
+ ["name"]=>
24
+ string(%d) "{closure:%s:%d}"
25
+ ["file"]=>
26
+ string(%d) "%s"
27
+ ["line"]=>
28
+ int(3)
29
+ ["static"]=>
30
+ array(2) {
31
+ ["x"]=>
32
+ array(0) {
33
+ }
34
+ ["i"]=>
35
+ int(1)
36
37
+}
38
+array(1) {
39
+ [0]=>
40
+ int(2)
41
42
+array(2) {
43
44
45
+ [1]=>
46
+ int(4)
47
48
+array(3) {
49
50
51
52
53
+ [2]=>
54
+ int(8)
55
56
57
58
59
60
61
62
63
64
65
66
+ array(3) {
67
68
69
70
71
72
73
74
75
76
77
Zend/zend_ast.c
@@ -1278,6 +1278,9 @@ static void* ZEND_FASTCALL zend_ast_tree_copy(zend_ast *ast, void *buf)
1278
new->lineno = old->lineno;
1279
new->op_array = old->op_array;
1280
function_add_ref((zend_function *)new->op_array);
1281
+ if (new->op_array->static_variables) {
1282
+ GC_TRY_ADDREF(new->op_array->static_variables);
1283
1284
buf = (void*)((char*)buf + sizeof(zend_ast_op_array));
1285
} else if (ast->kind == ZEND_AST_CALLABLE_CONVERT) {
1286
zend_ast_fcc *old = (zend_ast_fcc*)ast;
@@ -1354,6 +1357,9 @@ ZEND_API void ZEND_FASTCALL zend_ast_destroy(zend_ast *ast)
1354
1357
} else if (EXPECTED(ast->kind == ZEND_AST_CONSTANT)) {
1355
1358
zend_string_release_ex(zend_ast_get_constant_name(ast), 0);
1356
1359
} else if (EXPECTED(ast->kind == ZEND_AST_OP_ARRAY)) {
1360
+ if (zend_ast_get_op_array(ast)->op_array->static_variables) {
1361
+ zend_array_release(zend_ast_get_op_array(ast)->op_array->static_variables);
1362
1363
destroy_op_array(zend_ast_get_op_array(ast)->op_array);
1364
} else if (EXPECTED(zend_ast_is_decl(ast))) {
1365
zend_ast_decl *decl = (zend_ast_decl *) ast;