Skip to content

Commit

Permalink
Fix #49555: Improve "function must be a string" error message
Browse files Browse the repository at this point in the history
Be more specific for the individual cases and provide relevant
type information.
  • Loading branch information
nikic committed Jan 8, 2020
1 parent 33476ec commit d0d1654
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ PHP NEWS
(Fabien Villepinte)
. Fixed bug #65274 (Enhance undefined class constant error with class name).
(Nikita)
. Fixed bug #49555 (Fatal error "Function must be a string" message should be
renamed). (Nikita)

- Date:
. Fixed bug #65547 (Default value for sunrise/sunset zenith still wrong).
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/028.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool(true)

Notice: Undefined offset: 2 in %s on line %d

Fatal error: Uncaught Error: Function name must be a string in %s:%d
Fatal error: Uncaught Error: Value of type null is not callable in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/bug70124.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ try {
?>
--EXPECTF--
Warning: Undefined variable: f in %s on line %d
string(30) "Function name must be a string"
string(34) "Value of type null is not callable"
string(31) "Call to undefined method A::y()"
string(31) "Call to undefined method A::y()"
string(34) "Call to undefined function bar\y()"
Expand Down
4 changes: 2 additions & 2 deletions Zend/tests/dynamic_call_freeing.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ try {
?>
--EXPECT--
Call to undefined function foobar()
Function name must be a string
Function name must be a string
Array callback must have exactly two elements
Object of type stdClass is not callable
4 changes: 2 additions & 2 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -4036,7 +4036,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_object(zend_o
object_or_called_scope = object;
}
} else {
zend_throw_error(NULL, "Function name must be a string");
zend_throw_error(NULL, "Object of type %s is not callable", ZSTR_VAL(function->ce->name));
return NULL;
}

Expand Down Expand Up @@ -4121,7 +4121,7 @@ static zend_never_inline zend_execute_data *zend_init_dynamic_call_array(zend_ar
}
}
} else {
zend_throw_error(NULL, "Function name must be a string");
zend_throw_error(NULL, "Array callback must have exactly two elements");
return NULL;
}

Expand Down
5 changes: 3 additions & 2 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -3686,12 +3686,13 @@ ZEND_VM_C_LABEL(try_function_name):
ZEND_VM_C_GOTO(try_function_name);
} else {
if (OP2_TYPE == IS_CV && UNEXPECTED(Z_TYPE_P(function_name) == IS_UNDEF)) {
ZVAL_UNDEFINED_OP2();
function_name = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(EG(exception) != NULL)) {
HANDLE_EXCEPTION();
}
}
zend_throw_error(NULL, "Function name must be a string");
zend_throw_error(NULL, "Value of type %s is not callable",
zend_get_type_by_const(Z_TYPE_P(function_name)));
call = NULL;
}

Expand Down
15 changes: 9 additions & 6 deletions Zend/zend_vm_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -2876,12 +2876,13 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_DYNAMIC_CALL_SPEC_CONST_H
goto try_function_name;
} else {
if (IS_CONST == IS_CV && UNEXPECTED(Z_TYPE_P(function_name) == IS_UNDEF)) {
ZVAL_UNDEFINED_OP2();
function_name = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(EG(exception) != NULL)) {
HANDLE_EXCEPTION();
}
}
zend_throw_error(NULL, "Function name must be a string");
zend_throw_error(NULL, "Value of type %s is not callable",
zend_get_type_by_const(Z_TYPE_P(function_name)));
call = NULL;
}

Expand Down Expand Up @@ -3042,12 +3043,13 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_DYNAMIC_CALL_SPEC_TMPVAR_
goto try_function_name;
} else {
if ((IS_TMP_VAR|IS_VAR) == IS_CV && UNEXPECTED(Z_TYPE_P(function_name) == IS_UNDEF)) {
ZVAL_UNDEFINED_OP2();
function_name = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(EG(exception) != NULL)) {
HANDLE_EXCEPTION();
}
}
zend_throw_error(NULL, "Function name must be a string");
zend_throw_error(NULL, "Value of type %s is not callable",
zend_get_type_by_const(Z_TYPE_P(function_name)));
call = NULL;
}

Expand Down Expand Up @@ -3155,12 +3157,13 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_DYNAMIC_CALL_SPEC_CV_HAND
goto try_function_name;
} else {
if (IS_CV == IS_CV && UNEXPECTED(Z_TYPE_P(function_name) == IS_UNDEF)) {
ZVAL_UNDEFINED_OP2();
function_name = ZVAL_UNDEFINED_OP2();
if (UNEXPECTED(EG(exception) != NULL)) {
HANDLE_EXCEPTION();
}
}
zend_throw_error(NULL, "Function name must be a string");
zend_throw_error(NULL, "Value of type %s is not callable",
zend_get_type_by_const(Z_TYPE_P(function_name)));
call = NULL;
}

Expand Down

0 comments on commit d0d1654

Please sign in to comment.