Skip to content

Commit b15885b

Browse files
committed
Separate Closure::bind() implementations
Closure::bind() and Closure::bindTo() are currently reported as aliases in stubs because they have a single implementation. They are not aliases in fact though, they just use zend_parse_method_parameters() cleverly. Thus, let's separate their implementation so that we don't have to alias Closure::bindTo() anymore. This will also have the advantage that the two ZPP implementations become more clear. Closes GH-6169
1 parent f088aec commit b15885b

File tree

3 files changed

+30
-17
lines changed

3 files changed

+30
-17
lines changed

Zend/zend_closures.c

+26-11
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,10 @@ ZEND_METHOD(Closure, call)
192192
}
193193
/* }}} */
194194

195-
/* {{{ Create a closure from another one and bind to another object and scope */
196-
ZEND_METHOD(Closure, bind)
195+
static void do_closure_bind(zval *return_value, zval *zclosure, zval *newthis, zval *scope_arg)
197196
{
198-
zval *newthis, *zclosure, *scope_arg = NULL;
199-
zend_closure *closure;
200197
zend_class_entry *ce, *called_scope;
201-
202-
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oo!|z", &zclosure, zend_ce_closure, &newthis, &scope_arg) == FAILURE) {
203-
RETURN_THROWS();
204-
}
205-
206-
closure = (zend_closure *)Z_OBJ_P(zclosure);
198+
zend_closure *closure = (zend_closure *) Z_OBJ_P(zclosure);
207199

208200
if (scope_arg != NULL) { /* scope argument was given */
209201
if (Z_TYPE_P(scope_arg) == IS_OBJECT) {
@@ -238,7 +230,30 @@ ZEND_METHOD(Closure, bind)
238230

239231
zend_create_closure(return_value, &closure->func, ce, called_scope, newthis);
240232
}
241-
/* }}} */
233+
234+
/* {{{ Create a closure from another one and bind to another object and scope */
235+
ZEND_METHOD(Closure, bind)
236+
{
237+
zval *newthis, *zclosure, *scope_arg = NULL;
238+
239+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Oo!|z", &zclosure, zend_ce_closure, &newthis, &scope_arg) == FAILURE) {
240+
RETURN_THROWS();
241+
}
242+
243+
do_closure_bind(return_value, zclosure, newthis, scope_arg);
244+
}
245+
246+
/* {{{ Create a closure from another one and bind to another object and scope */
247+
ZEND_METHOD(Closure, bindTo)
248+
{
249+
zval *newthis, *scope_arg = NULL;
250+
251+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o!|z", &newthis, &scope_arg) == FAILURE) {
252+
RETURN_THROWS();
253+
}
254+
255+
do_closure_bind(return_value, getThis(), newthis, scope_arg);
256+
}
242257

243258
static ZEND_NAMED_FUNCTION(zend_closure_call_magic) /* {{{ */ {
244259
zend_fcall_info fci;

Zend/zend_closures.stub.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ private function __construct() {}
99
/** @param object|string|null $newScope */
1010
public static function bind(Closure $closure, ?object $newThis, $newScope = UNKNOWN): ?Closure {}
1111

12-
/**
13-
* @param object|string|null $newScope
14-
* @alias Closure::bind
15-
*/
12+
/** @param object|string|null $newScope */
1613
public function bindTo(?object $newThis, $newScope = UNKNOWN): ?Closure {}
1714

1815
public function call(object $newThis, mixed ...$arguments): mixed {}

Zend/zend_closures_arginfo.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 124654da4652ea828875f471a2ddcc4afae147ae */
2+
* Stub hash: abbbe7b04323dc44b0675ad58700e996a6d7c43b */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Closure___construct, 0, 0, 0)
55
ZEND_END_ARG_INFO()
@@ -27,14 +27,15 @@ ZEND_END_ARG_INFO()
2727

2828
ZEND_METHOD(Closure, __construct);
2929
ZEND_METHOD(Closure, bind);
30+
ZEND_METHOD(Closure, bindTo);
3031
ZEND_METHOD(Closure, call);
3132
ZEND_METHOD(Closure, fromCallable);
3233

3334

3435
static const zend_function_entry class_Closure_methods[] = {
3536
ZEND_ME(Closure, __construct, arginfo_class_Closure___construct, ZEND_ACC_PRIVATE)
3637
ZEND_ME(Closure, bind, arginfo_class_Closure_bind, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
37-
ZEND_MALIAS(Closure, bindTo, bind, arginfo_class_Closure_bindTo, ZEND_ACC_PUBLIC)
38+
ZEND_ME(Closure, bindTo, arginfo_class_Closure_bindTo, ZEND_ACC_PUBLIC)
3839
ZEND_ME(Closure, call, arginfo_class_Closure_call, ZEND_ACC_PUBLIC)
3940
ZEND_ME(Closure, fromCallable, arginfo_class_Closure_fromCallable, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
4041
ZEND_FE_END

0 commit comments

Comments
 (0)