com php-src: Added optional bool param $unbound_scoped to Closure::bind and ::bindTo: Zend/zend_clos ures.c Zend/zend_closures.h
| From: | Tjerk Anne Meesters | Date: | Tue, 29 Jul 2014 17:59:36 +0000 |
| Subject: | com php-src: Added optional bool param $unbound_scoped to Closure::bind and ::bindTo: Zend/zend_clos ures.c Zend/zend_closures.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-81168@lists.php.net to get a copy of this message | ||
Commit: ded5b3fda44a76b010242a2c57dab4ad9f48e1bd
Author: Andrea Faulds <ajf@ajf.me> Tue, 29 Jul 2014 03:18:04 +0100
Parents: 167128d854076d5ca1192725daeb12fe92d76436
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=ded5b3fda44a76b010242a2c57dab4ad9f48e1bd
Log:
Added optional bool param $unbound_scoped to Closure::bind and ::bindTo
Changed paths:
M Zend/zend_closures.c
M Zend/zend_closures.h
Diff:
diff --git a/Zend/zend_closures.c b/Zend/zend_closures.c
index c2d9de4..39f5a0e 100644
--- a/Zend/zend_closures.c
+++ b/Zend/zend_closures.c
@@ -125,15 +125,16 @@ ZEND_METHOD(Closure, apply) /* {{{ */
}
/* }}} */
-/* {{{ proto Closure Closure::bind(Closure $old, object $to [, mixed $scope = "static" ]
)
+/* {{{ proto Closure Closure::bind(Closure $old, object $to [, mixed $scope = "static" ]
[, bool $unbound_scoped = false ] )
Create a closure from another one and bind to another object and scope */
ZEND_METHOD(Closure, bind)
{
zval *newthis, *zclosure, *scope_arg = NULL;
zend_closure *closure;
zend_class_entry *ce, **ce_p;
+ zend_bool unbound_scoped = false;
- if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oo!|z",
&zclosure, zend_ce_closure, &newthis, &scope_arg) == FAILURE) {
+ if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oo!|zb",
&zclosure, zend_ce_closure, &newthis, &scope_arg, &unbound_scoped) == FAILURE) {
RETURN_NULL();
}
@@ -182,7 +183,7 @@ ZEND_METHOD(Closure, bind)
ce = closure->func.common.scope;
}
- zend_create_closure(return_value, &closure->func, ce, newthis TSRMLS_CC);
+ zend_create_closure_ex(return_value, &closure->func, ce, newthis, unbound_scoped
TSRMLS_CC);
}
/* }}} */
@@ -446,12 +447,14 @@ ZEND_METHOD(Closure, __construct)
ZEND_BEGIN_ARG_INFO_EX(arginfo_closure_bindto, 0, 0, 1)
ZEND_ARG_INFO(0, newthis)
ZEND_ARG_INFO(0, newscope)
+ ZEND_ARG_INFO(0, unbound_scoped)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_closure_bind, 0, 0, 2)
ZEND_ARG_INFO(0, closure)
ZEND_ARG_INFO(0, newthis)
ZEND_ARG_INFO(0, newscope)
+ ZEND_ARG_INFO(0, unbound_scoped)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_closure_apply, 0, 0, 1)
@@ -496,6 +499,11 @@ void zend_register_closure_ce(TSRMLS_D) /* {{{ */
ZEND_API void zend_create_closure(zval *res, zend_function *func, zend_class_entry *scope, zval
*this_ptr TSRMLS_DC) /* {{{ */
{
+ zend_create_closure_ex(res, func, scope, this_ptr, 0 TSRMLS_CC);
+}
+
+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) /* {{{ */
+{
zend_closure *closure;
object_init_ex(res, zend_ce_closure);
@@ -543,15 +551,17 @@ ZEND_API void zend_create_closure(zval *res, zend_function *func,
zend_class_ent
closure->this_ptr = NULL;
/* Invariants:
- * If the closure is unscoped, it has no bound object.
- * The the closure is scoped, it's either static or it's bound */
+ * If the closure is unscoped, it is unbound.
+ * If the closure is scoped, it may be static, bound or unbound */
closure->func.common.scope = scope;
if (scope) {
closure->func.common.fn_flags |= ZEND_ACC_PUBLIC;
if (this_ptr && (closure->func.common.fn_flags & ZEND_ACC_STATIC) == 0) {
closure->this_ptr = this_ptr;
Z_ADDREF_P(this_ptr);
- } else {
+ /* We assume that a static scoped closure is desired if given NULL to bind to
+ If an unbound scoped closure is desired, the parameter must be set to 1*/
+ } else if (!unbound_scoped) {
closure->func.common.fn_flags |= ZEND_ACC_STATIC;
}
}
diff --git a/Zend/zend_closures.h b/Zend/zend_closures.h
index fa66e97..d916d5e 100644
--- a/Zend/zend_closures.h
+++ b/Zend/zend_closures.h
@@ -29,6 +29,7 @@ void zend_register_closure_ce(TSRMLS_D);
extern ZEND_API zend_class_entry *zend_ce_closure;
ZEND_API void zend_create_closure(zval *res, zend_function *op_array, zend_class_entry *scope, zval
*this_ptr TSRMLS_DC);
+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);
ZEND_API zend_function *zend_get_closure_invoke_method(zval *obj TSRMLS_DC);
ZEND_API const zend_function *zend_get_closure_method_def(zval *obj TSRMLS_DC);
ZEND_API zval* zend_get_closure_this_ptr(zval *obj TSRMLS_DC);