Skip to content

Commit c6d89bd

Browse files
author
Christian Seiler
committed
[DOC] Remove $this support in closures for PHP 5.3 beta 1
- Implementation notes here: http://wiki.php.net/rfc/closures/removal-of-this
1 parent 7cb513c commit c6d89bd

22 files changed

+113
-693
lines changed

Zend/tests/closure_005.phpt

-74
This file was deleted.

Zend/tests/closure_007.phpt

-38
This file was deleted.

Zend/tests/closure_020.phpt

+2-19
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,15 @@ object(foo)#%d (%d) {
2727
["test":"foo":private]=>
2828
int(3)
2929
["a"]=>
30-
object(Closure)#%d (2) {
31-
["this"]=>
32-
object(foo)#%d (2) {
33-
["test":"foo":private]=>
34-
int(3)
35-
["a"]=>
36-
object(Closure)#%d (2) {
37-
["this"]=>
38-
*RECURSION*
39-
["static"]=>
40-
array(1) {
41-
["a"]=>
42-
*RECURSION*
43-
}
44-
}
45-
}
30+
object(Closure)#%d (1) {
4631
["static"]=>
4732
array(1) {
4833
["a"]=>
4934
&object(foo)#%d (2) {
5035
["test":"foo":private]=>
5136
int(3)
5237
["a"]=>
53-
object(Closure)#%d (2) {
54-
["this"]=>
55-
*RECURSION*
38+
object(Closure)#%d (1) {
5639
["static"]=>
5740
array(1) {
5841
["a"]=>

Zend/tests/closure_026.phpt

+2-27
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,7 @@ object(foo)#%d (1) {
3232
["a"]=>
3333
array(1) {
3434
[0]=>
35-
object(Closure)#%d (1) {
36-
["this"]=>
37-
object(foo)#%d (1) {
38-
["a"]=>
39-
array(1) {
40-
[0]=>
41-
object(Closure)#%d (1) {
42-
["this"]=>
43-
*RECURSION*
44-
}
45-
}
46-
}
35+
object(Closure)#%d (0) {
4736
}
4837
}
4938
}
@@ -52,21 +41,7 @@ int(1)
5241
string(1) "a"
5342
array(1) {
5443
[0]=>
55-
object(Closure)#%d (1) {
56-
["this"]=>
57-
object(foo)#%d (1) {
58-
["a"]=>
59-
array(1) {
60-
[0]=>
61-
object(Closure)#%d (1) {
62-
["this"]=>
63-
object(foo)#%d (1) {
64-
["a"]=>
65-
*RECURSION*
66-
}
67-
}
68-
}
69-
}
44+
object(Closure)#%d (0) {
7045
}
7146
}
7247
int(1)

Zend/tests/closure_032.phpt

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ Array
5353
(
5454
[0] => Closure Object
5555
(
56-
[this] =>
5756
[parameter] => Array
5857
(
5958
[$param] => <required>

Zend/zend_closures.c

+5-43
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
typedef struct _zend_closure {
3838
zend_object std;
3939
zend_function func;
40-
zval *this_ptr;
4140
} zend_closure;
4241

4342
/* non-static since it needs to be referenced */
@@ -111,13 +110,6 @@ ZEND_API const zend_function *zend_get_closure_method_def(zval *obj TSRMLS_DC) /
111110
}
112111
/* }}} */
113112

114-
ZEND_API zval* zend_get_closure_this_ptr(zval *obj TSRMLS_DC) /* {{{ */
115-
{
116-
zend_closure *closure = (zend_closure *)zend_object_store_get_object(obj TSRMLS_CC);
117-
return closure->this_ptr;
118-
}
119-
/* }}} */
120-
121113
static zend_function *zend_closure_get_method(zval **object_ptr, char *method_name, int method_len TSRMLS_DC) /* {{{ */
122114
{
123115
char *lc_name;
@@ -187,10 +179,6 @@ static void zend_closure_free_storage(void *object TSRMLS_DC) /* {{{ */
187179
destroy_op_array(&closure->func.op_array TSRMLS_CC);
188180
}
189181

190-
if (closure->this_ptr) {
191-
zval_ptr_dtor(&closure->this_ptr);
192-
}
193-
194182
efree(closure);
195183
}
196184
/* }}} */
@@ -223,17 +211,10 @@ int zend_closure_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function
223211
closure = (zend_closure *)zend_object_store_get_object(obj TSRMLS_CC);
224212
*fptr_ptr = &closure->func;
225213

226-
if (closure->this_ptr) {
227-
if (zobj_ptr) {
228-
*zobj_ptr = closure->this_ptr;
229-
}
230-
*ce_ptr = Z_OBJCE_P(closure->this_ptr);
231-
} else {
232-
if (zobj_ptr) {
233-
*zobj_ptr = NULL;
234-
}
235-
*ce_ptr = closure->func.common.scope;
214+
if (zobj_ptr) {
215+
*zobj_ptr = NULL;
236216
}
217+
*ce_ptr = NULL;
237218
return SUCCESS;
238219
}
239220
/* }}} */
@@ -248,13 +229,6 @@ static HashTable *zend_closure_get_debug_info(zval *object, int *is_temp TSRMLS_
248229
*is_temp = 1;
249230
ALLOC_HASHTABLE(rv);
250231
zend_hash_init(rv, 1, NULL, ZVAL_PTR_DTOR, 0);
251-
val = closure->this_ptr;
252-
if (!val) {
253-
ALLOC_INIT_ZVAL(val);
254-
} else {
255-
Z_ADDREF_P(val);
256-
}
257-
zend_symtable_update(rv, "this", sizeof("this"), (void *) &val, sizeof(zval *), NULL);
258232
if (closure->func.type == ZEND_USER_FUNCTION && closure->func.op_array.static_variables) {
259233
HashTable *static_variables = closure->func.op_array.static_variables;
260234
MAKE_STD_ZVAL(val);
@@ -369,7 +343,7 @@ static int zval_copy_static_var(zval **p TSRMLS_DC, int num_args, va_list args,
369343
}
370344
/* }}} */
371345

372-
ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_entry *scope, zval *this_ptr TSRMLS_DC) /* {{{ */
346+
ZEND_API void zend_create_closure(zval *res, zend_function *func TSRMLS_DC) /* {{{ */
373347
{
374348
zend_closure *closure;
375349

@@ -390,19 +364,7 @@ ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_ent
390364
(*closure->func.op_array.refcount)++;
391365
}
392366

393-
closure->func.common.scope = scope;
394-
if (scope) {
395-
closure->func.common.fn_flags |= ZEND_ACC_PUBLIC;
396-
if (this_ptr && (closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0) {
397-
closure->this_ptr = this_ptr;
398-
Z_ADDREF_P(this_ptr);
399-
} else {
400-
closure->func.common.fn_flags |= ZEND_ACC_STATIC;
401-
closure->this_ptr = NULL;
402-
}
403-
} else {
404-
closure->this_ptr = NULL;
405-
}
367+
closure->func.common.scope = NULL;
406368
}
407369
/* }}} */
408370

Zend/zend_closures.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ void zend_register_closure_ce(TSRMLS_D);
3030

3131
extern ZEND_API zend_class_entry *zend_ce_closure;
3232

33-
ZEND_API void zend_create_closure(zval *res, zend_function *op_array, zend_class_entry *scope, zval *this_ptr TSRMLS_DC);
34-
ZEND_API int zend_get_closure(zval *obj, zend_class_entry **ce_ptr, zend_function **fptr_ptr, zval **zobj_ptr, zval ***zobj_ptr_ptr TSRMLS_DC);
33+
ZEND_API void zend_create_closure(zval *res, zend_function *op_array TSRMLS_DC);
3534
ZEND_API zend_function *zend_get_closure_invoke_method(zval *obj TSRMLS_DC);
3635
ZEND_API const zend_function *zend_get_closure_method_def(zval *obj TSRMLS_DC);
37-
ZEND_API zval* zend_get_closure_this_ptr(zval *obj TSRMLS_DC);
3836

3937
END_EXTERN_C()
4038

Zend/zend_compile.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ void zend_do_begin_function_declaration(znode *function_token, znode *function_n
13891389
CG(labels) = NULL;
13901390
}
13911391

1392-
void zend_do_begin_lambda_function_declaration(znode *result, znode *function_token, int return_reference, int is_static TSRMLS_DC)
1392+
void zend_do_begin_lambda_function_declaration(znode *result, znode *function_token, int return_reference TSRMLS_DC)
13931393
{
13941394
znode function_name;
13951395
zend_op_array *current_op_array = CG(active_op_array);
@@ -1409,9 +1409,6 @@ void zend_do_begin_lambda_function_declaration(znode *result, znode *function_to
14091409
zval_dtor(&current_op->op2.u.constant);
14101410
ZVAL_LONG(&current_op->op2.u.constant, zend_hash_func(Z_STRVAL(current_op->op1.u.constant), Z_STRLEN(current_op->op1.u.constant)));
14111411
current_op->result = *result;
1412-
if (is_static) {
1413-
CG(active_op_array)->fn_flags |= ZEND_ACC_STATIC;
1414-
}
14151412
CG(active_op_array)->fn_flags |= ZEND_ACC_CLOSURE;
14161413
}
14171414

Zend/zend_compile.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ void zend_do_end_function_call(znode *function_name, znode *result, const znode
434434
void zend_do_return(znode *expr, int do_end_vparse TSRMLS_DC);
435435
void zend_do_handle_exception(TSRMLS_D);
436436

437-
void zend_do_begin_lambda_function_declaration(znode *result, znode *function_token, int return_reference, int is_static TSRMLS_DC);
437+
void zend_do_begin_lambda_function_declaration(znode *result, znode *function_token, int return_reference TSRMLS_DC);
438438
void zend_do_fetch_lexical_variable(znode *varname, zend_bool is_ref TSRMLS_DC);
439439

440440
void zend_do_try(znode *try_token TSRMLS_DC);

Zend/zend_language_parser.y

+1-3
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,8 @@ expr_without_variable:
647647
| T_ARRAY '(' array_pair_list ')' { $$ = $3; }
648648
| '`' backticks_expr '`' { zend_do_shell_exec(&$$, &$2 TSRMLS_CC); }
649649
| T_PRINT expr { zend_do_print(&$$, &$2 TSRMLS_CC); }
650-
| function is_reference '(' { zend_do_begin_lambda_function_declaration(&$$, &$1, $2.op_type, 0 TSRMLS_CC); }
650+
| function is_reference '(' { zend_do_begin_lambda_function_declaration(&$$, &$1, $2.op_type TSRMLS_CC); }
651651
parameter_list ')' lexical_vars '{' inner_statement_list '}' { zend_do_end_function_declaration(&$1 TSRMLS_CC); $$ = $4; }
652-
| T_STATIC function is_reference '(' { zend_do_begin_lambda_function_declaration(&$$, &$2, $3.op_type, 1 TSRMLS_CC); }
653-
parameter_list ')' lexical_vars '{' inner_statement_list '}' { zend_do_end_function_declaration(&$2 TSRMLS_CC); $$ = $5; }
654652
;
655653

656654
function:

Zend/zend_vm_def.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -4393,7 +4393,7 @@ ZEND_VM_HANDLER(153, ZEND_DECLARE_LAMBDA_FUNCTION, CONST, CONST)
43934393
zend_error_noreturn(E_ERROR, "Base lambda function for closure not found");
43944394
}
43954395

4396-
zend_create_closure(&EX_T(opline->result.u.var).tmp_var, op_array, EG(scope), EG(This) TSRMLS_CC);
4396+
zend_create_closure(&EX_T(opline->result.u.var).tmp_var, op_array TSRMLS_CC);
43974397

43984398
ZEND_VM_NEXT_OPCODE();
43994399
}

Zend/zend_vm_execute.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2912,7 +2912,7 @@ static int ZEND_FASTCALL ZEND_DECLARE_LAMBDA_FUNCTION_SPEC_CONST_CONST_HANDLER(
29122912
zend_error_noreturn(E_ERROR, "Base lambda function for closure not found");
29132913
}
29142914

2915-
zend_create_closure(&EX_T(opline->result.u.var).tmp_var, op_array, EG(scope), EG(This) TSRMLS_CC);
2915+
zend_create_closure(&EX_T(opline->result.u.var).tmp_var, op_array TSRMLS_CC);
29162916

29172917
ZEND_VM_NEXT_OPCODE();
29182918
}

0 commit comments

Comments
 (0)