]> granicus.if.org Git - php/commitdiff
Correctly determine arg name of USER_ARG_INFO functions
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 6 Jul 2020 09:49:56 +0000 (11:49 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 6 Jul 2020 09:51:10 +0000 (11:51 +0200)
Zend/tests/closure_invoke_ref_warning.phpt [new file with mode: 0644]
Zend/zend_execute_API.c

diff --git a/Zend/tests/closure_invoke_ref_warning.phpt b/Zend/tests/closure_invoke_ref_warning.phpt
new file mode 100644 (file)
index 0000000..08eefd3
--- /dev/null
@@ -0,0 +1,13 @@
+--TEST--
+Argument name for Closure::__invoke via call_user_func reference warning
+--FILE--
+<?php
+
+$test = function(&$arg) {};
+call_user_func([$test, '__invoke'], null);
+
+?>
+--EXPECTF--
+Warning: Closure::__invoke(): Argument #1 ($arg) must be passed by reference, value given in %s on line %d
+
+Warning: {closure}(): Argument #1 ($arg) must be passed by reference, value given in %s on line %d
index a646bceb0b8a7d8a17d433cd2143f95c3f81004d..ab5766af27b199006e94f82f5302fe61d22eb3d7 100644 (file)
@@ -507,13 +507,10 @@ ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t a
                return NULL;
        }
 
-       switch (func->type) {
-               case ZEND_USER_FUNCTION:
-                       return ZSTR_VAL(func->common.arg_info[arg_num - 1].name);
-               case ZEND_INTERNAL_FUNCTION:
-                       return ((zend_internal_arg_info*) func->common.arg_info)[arg_num - 1].name;
-               default:
-                       return NULL;
+       if (func->type == ZEND_USER_FUNCTION || (func->common.fn_flags & ZEND_ACC_USER_ARG_INFO)) {
+               return ZSTR_VAL(func->common.arg_info[arg_num - 1].name);
+       } else {
+               return ((zend_internal_arg_info*) func->common.arg_info)[arg_num - 1].name;
        }
 }
 /* }}} */