Skip to content

Commit 7743876

Browse files
Better parameter naming and clearer comments
1 parent 63ccf4f commit 7743876

4 files changed

Lines changed: 11 additions & 9 deletions

File tree

‎Zend/zend_closures.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,10 @@ void zend_register_closure_ce(TSRMLS_D) /* {{{ */
435435

436436
ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_entry *scope, zval *this_ptr TSRMLS_DC) /* {{{ */
437437
{
438-
zend_create_closure_ex(res, func, scope, this_ptr, 1 TSRMLS_CC);
438+
zend_create_closure_ex(res, func, scope, this_ptr, 0 TSRMLS_CC);
439439
}
440440

441-
ZEND_API void zend_create_closure_ex(zval *res, zend_function *func, zend_class_entry *scope, zval *this_ptr, zend_bool assume_static TSRMLS_DC) /* {{{ */
441+
ZEND_API void zend_create_closure_ex(zval *res, zend_function *func, zend_class_entry *scope, zval *this_ptr, zend_bool unbound_scoped TSRMLS_DC) /* {{{ */
442442
{
443443
zend_closure *closure;
444444

@@ -487,15 +487,17 @@ ZEND_API void zend_create_closure_ex(zval *res, zend_function *func, zend_class_
487487

488488
closure->this_ptr = NULL;
489489
/* Invariants:
490-
* If the closure is unscoped, it has no bound object.
491-
* The the closure is scoped, it's either static or it's bound */
490+
* If the closure is unscoped, it is unbound.
491+
* If the closure is scoped, it may be static, bound or unbound */
492492
closure->func.common.scope = scope;
493493
if (scope) {
494494
closure->func.common.fn_flags |= ZEND_ACC_PUBLIC;
495495
if (this_ptr && (closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0) {
496496
closure->this_ptr = this_ptr;
497497
Z_ADDREF_P(this_ptr);
498-
} else if (assume_static) {
498+
/* We assume that a static scoped closure is desired if given NULL to bind to
499+
If an unbound scoped closure is desired, the parameter must be set to 1*/
500+
} else if (!unbound_scoped) {
499501
closure->func.common.fn_flags |= ZEND_ACC_STATIC;
500502
}
501503
}

‎Zend/zend_closures.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void zend_register_closure_ce(TSRMLS_D);
2929
extern ZEND_API zend_class_entry *zend_ce_closure;
3030

3131
ZEND_API void zend_create_closure(zval *res, zend_function *op_array, zend_class_entry *scope, zval *this_ptr TSRMLS_DC);
32-
ZEND_API void zend_create_closure_ex(zval *res, zend_function *op_array, zend_class_entry *scope, zval *this_ptr, zend_bool assume_static TSRMLS_DC);
32+
ZEND_API void zend_create_closure_ex(zval *res, zend_function *op_array, zend_class_entry *scope, zval *this_ptr, zend_bool unbound_scoped TSRMLS_DC);
3333
ZEND_API zend_function *zend_get_closure_invoke_method(zval *obj TSRMLS_DC);
3434
ZEND_API const zend_function *zend_get_closure_method_def(zval *obj TSRMLS_DC);
3535
ZEND_API zval* zend_get_closure_this_ptr(zval *obj TSRMLS_DC);

‎Zend/zend_vm_def.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2831,7 +2831,7 @@ ZEND_VM_HANDLER(168, ZEND_FUNCTION_REFERENCE, CONST|UNUSED, CONST)
28312831
zend_error_noreturn(E_RECOVERABLE_ERROR, "Reference to undefined method %s::%s", Z_STRVAL(class_name->constant), Z_STRVAL(func_name->constant));
28322832
}
28332833

2834-
zend_create_closure_ex(&EX_T(opline->result.var).tmp_var, function, ce, NULL, 0 TSRMLS_CC);
2834+
zend_create_closure_ex(&EX_T(opline->result.var).tmp_var, function, ce, NULL, 1 TSRMLS_CC);
28352835
} else {
28362836
if (UNEXPECTED(zend_hash_quick_find(EG(function_table), Z_STRVAL(func_name->constant), Z_STRLEN(func_name->constant) + 1, Z_HASH_P(&func_name->constant), (void **) &function) == FAILURE)) {
28372837
zend_error_noreturn(E_RECOVERABLE_ERROR, "Reference to undefined function %s", Z_STRVAL(func_name->constant));

‎Zend/zend_vm_execute.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3960,7 +3960,7 @@ static int ZEND_FASTCALL ZEND_FUNCTION_REFERENCE_SPEC_CONST_CONST_HANDLER(ZEND_
39603960
zend_error_noreturn(E_RECOVERABLE_ERROR, "Reference to undefined method %s::%s", Z_STRVAL(class_name->constant), Z_STRVAL(func_name->constant));
39613961
}
39623962

3963-
zend_create_closure_ex(&EX_T(opline->result.var).tmp_var, function, ce, NULL, 0 TSRMLS_CC);
3963+
zend_create_closure_ex(&EX_T(opline->result.var).tmp_var, function, ce, NULL, 1 TSRMLS_CC);
39643964
} else {
39653965
if (UNEXPECTED(zend_hash_quick_find(EG(function_table), Z_STRVAL(func_name->constant), Z_STRLEN(func_name->constant) + 1, Z_HASH_P(&func_name->constant), (void **) &function) == FAILURE)) {
39663966
zend_error_noreturn(E_RECOVERABLE_ERROR, "Reference to undefined function %s", Z_STRVAL(func_name->constant));
@@ -25589,7 +25589,7 @@ static int ZEND_FASTCALL ZEND_FUNCTION_REFERENCE_SPEC_UNUSED_CONST_HANDLER(ZEND
2558925589
zend_error_noreturn(E_RECOVERABLE_ERROR, "Reference to undefined method %s::%s", Z_STRVAL(class_name->constant), Z_STRVAL(func_name->constant));
2559025590
}
2559125591

25592-
zend_create_closure_ex(&EX_T(opline->result.var).tmp_var, function, ce, NULL, 0 TSRMLS_CC);
25592+
zend_create_closure_ex(&EX_T(opline->result.var).tmp_var, function, ce, NULL, 1 TSRMLS_CC);
2559325593
} else {
2559425594
if (UNEXPECTED(zend_hash_quick_find(EG(function_table), Z_STRVAL(func_name->constant), Z_STRLEN(func_name->constant) + 1, Z_HASH_P(&func_name->constant), (void **) &function) == FAILURE)) {
2559525595
zend_error_noreturn(E_RECOVERABLE_ERROR, "Reference to undefined function %s", Z_STRVAL(func_name->constant));

0 commit comments

Comments
 (0)