mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Make type error messages more consistent
Closes GH-5092
This commit is contained in:
parent
72bd55902d
commit
ac0853eb26
389 changed files with 1680 additions and 1693 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue