diff options
author | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-01-29 20:06:13 +0100 |
---|---|---|
committer | Máté Kocsis <kocsismate@woohoolabs.com> | 2020-02-17 14:22:17 +0100 |
commit | ac0853eb265784c4238af652de9c54c883ffa99f (patch) | |
tree | e9316872480304e9e74ce89bd15052965cc18438 /Zend/zend_execute_API.c | |
parent | 72bd55902d1908857f47555ad69458861e1acd94 (diff) | |
download | php-git-ac0853eb265784c4238af652de9c54c883ffa99f.tar.gz |
Make type error messages more consistent
Closes GH-5092
Diffstat (limited to 'Zend/zend_execute_API.c')
-rw-r--r-- | Zend/zend_execute_API.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index e2410cf6af..80d0cf26ee 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -488,6 +488,37 @@ ZEND_API const char *get_active_function_name(void) /* {{{ */ } /* }}} */ +ZEND_API const char *get_active_function_arg_name(uint32_t arg_num) /* {{{ */ +{ + zend_function *func; + + if (!zend_is_executing()) { + return NULL; + } + + func = EG(current_execute_data)->func; + + return get_function_arg_name(func, arg_num); +} +/* }}} */ + +ZEND_API const char *get_function_arg_name(const zend_function *func, uint32_t arg_num) /* {{{ */ +{ + if (!func || func->common.num_args < arg_num) { + 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; + } +} +/* }}} */ + ZEND_API const char *zend_get_executed_filename(void) /* {{{ */ { zend_execute_data *ex = EG(current_execute_data); @@ -717,11 +748,18 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache) / } else if (!ARG_MAY_BE_SENT_BY_REF(func, i + 1)) { /* By-value send is not allowed -- emit a warning, * but still perform the call with a by-value send. */ + const char *arg_name = get_function_arg_name(func, i + 1); + zend_error(E_WARNING, - "Parameter %d to %s%s%s() expected to be a reference, value given", i+1, + "%s%s%s() expects argument #%d%s%s%s to be passed by reference, value given", func->common.scope ? ZSTR_VAL(func->common.scope->name) : "", func->common.scope ? "::" : "", - ZSTR_VAL(func->common.function_name)); + ZSTR_VAL(func->common.function_name), + i+1, + arg_name ? " ($" : "", + arg_name ? arg_name : "", + arg_name ? ")" : "" + ); if (UNEXPECTED(EG(exception))) { ZEND_CALL_NUM_ARGS(call) = i; zend_vm_stack_free_args(call); |