]> granicus.if.org Git - php/commitdiff
Separate Closure::bind() implementations
authorMáté Kocsis <kocsismate@woohoolabs.com>
Sat, 19 Sep 2020 17:04:35 +0000 (19:04 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Sat, 19 Sep 2020 18:14:22 +0000 (20:14 +0200)
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

Zend/zend_closures.c
Zend/zend_closures.stub.php
Zend/zend_closures_arginfo.h

index 630857f26c1df56af8a19ee9086867ed67e2802c..86cabf0a10d846898d0082c09fa4825fff559a9f 100644 (file)
@@ -192,18 +192,10 @@ ZEND_METHOD(Closure, call)
 }
 /* }}} */
 
-/* {{{ Create a closure from another one and bind to another object and scope */
-ZEND_METHOD(Closure, bind)
+static 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) {
@@ -238,7 +230,30 @@ ZEND_METHOD(Closure, bind)
 
        zend_create_closure(return_value, &closure->func, ce, called_scope, newthis);
 }
-/* }}} */
+
+/* {{{ 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;
index b7df588fe9d5ab857dd466c5847e446b8b42598d..70e555bff2dc432ae083e346671612e5049e2bcc 100644 (file)
@@ -9,10 +9,7 @@ final class Closure
     /** @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 {}
index fe3407232b84e4d25845c440b6a8ec0f5f0b6ba6..f09023b132d0f7a0cad3434bfde99ada51f3d983 100644 (file)
@@ -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()
@@ -27,6 +27,7 @@ ZEND_END_ARG_INFO()
 
 ZEND_METHOD(Closure, __construct);
 ZEND_METHOD(Closure, bind);
+ZEND_METHOD(Closure, bindTo);
 ZEND_METHOD(Closure, call);
 ZEND_METHOD(Closure, fromCallable);
 
@@ -34,7 +35,7 @@ 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