Skip to content

Separate Closure::bind() implementations #6169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions Zend/zend_closures.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,11 @@ ZEND_METHOD(Closure, call)
}
/* }}} */

/* {{{ Create a closure from another one and bind to another object and scope */
ZEND_METHOD(Closure, bind)

static zend_always_inline void do_closure_bind(zval *return_value, zval *zclosure, zval *newthis, zval *scope_arg)
{
zval *newthis, *zclosure, *scope_arg = NULL;
zend_closure *closure;
zend_class_entry *ce, *called_scope;

if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oo!|z", &zclosure, zend_ce_closure, &newthis, &scope_arg) == FAILURE) {
RETURN_THROWS();
}

closure = (zend_closure *)Z_OBJ_P(zclosure);
zend_closure *closure = (zend_closure *) Z_OBJ_P(zclosure);

if (scope_arg != NULL) { /* scope argument was given */
if (Z_TYPE_P(scope_arg) == IS_OBJECT) {
Expand Down Expand Up @@ -240,6 +233,30 @@ ZEND_METHOD(Closure, bind)
}
/* }}} */

/* {{{ Create a closure from another one and bind to another object and scope */
ZEND_METHOD(Closure, bind)
{
zval *newthis, *zclosure, *scope_arg = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oo!|z", &zclosure, zend_ce_closure, &newthis, &scope_arg) == FAILURE) {
RETURN_THROWS();
}

do_closure_bind(return_value, zclosure, newthis, scope_arg);
}

/* {{{ Create a closure from another one and bind to another object and scope */
ZEND_METHOD(Closure, bindTo)
{
zval *newthis, *scope_arg = NULL;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "o!|z", &newthis, &scope_arg) == FAILURE) {
RETURN_THROWS();
}

do_closure_bind(return_value, getThis(), newthis, scope_arg);
}

static ZEND_NAMED_FUNCTION(zend_closure_call_magic) /* {{{ */ {
zend_fcall_info fci;
zend_fcall_info_cache fcc;
Expand Down
5 changes: 1 addition & 4 deletions Zend/zend_closures.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ private function __construct() {}
/** @param object|string|null $newScope */
public static function bind(Closure $closure, ?object $newThis, $newScope = UNKNOWN): ?Closure {}

/**
* @param object|string|null $newScope
* @alias Closure::bind
*/
/** @param object|string|null $newScope */
public function bindTo(?object $newThis, $newScope = UNKNOWN): ?Closure {}

public function call(object $newThis, mixed ...$arguments): mixed {}
Expand Down
5 changes: 3 additions & 2 deletions Zend/zend_closures_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 124654da4652ea828875f471a2ddcc4afae147ae */
* Stub hash: abbbe7b04323dc44b0675ad58700e996a6d7c43b */

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Closure___construct, 0, 0, 0)
ZEND_END_ARG_INFO()
Expand Down Expand Up @@ -27,14 +27,15 @@ ZEND_END_ARG_INFO()

ZEND_METHOD(Closure, __construct);
ZEND_METHOD(Closure, bind);
ZEND_METHOD(Closure, bindTo);
ZEND_METHOD(Closure, call);
ZEND_METHOD(Closure, fromCallable);


static const zend_function_entry class_Closure_methods[] = {
ZEND_ME(Closure, __construct, arginfo_class_Closure___construct, ZEND_ACC_PRIVATE)
ZEND_ME(Closure, bind, arginfo_class_Closure_bind, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
ZEND_MALIAS(Closure, bindTo, bind, arginfo_class_Closure_bindTo, ZEND_ACC_PUBLIC)
ZEND_ME(Closure, bindTo, arginfo_class_Closure_bindTo, ZEND_ACC_PUBLIC)
ZEND_ME(Closure, call, arginfo_class_Closure_call, ZEND_ACC_PUBLIC)
ZEND_ME(Closure, fromCallable, arginfo_class_Closure_fromCallable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
ZEND_FE_END
Expand Down