]> granicus.if.org Git - php/commitdiff
Fix #49555: Improve "function must be a string" error message
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 8 Jan 2020 13:32:11 +0000 (14:32 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 8 Jan 2020 13:32:11 +0000 (14:32 +0100)
Be more specific for the individual cases and provide relevant
type information.

NEWS
Zend/tests/028.phpt
Zend/tests/bug70124.phpt
Zend/tests/dynamic_call_freeing.phpt
Zend/zend_execute.c
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/NEWS b/NEWS
index f1909fda44245680469f41c1053470a4a625d32b..d46a30a3798fd29ba06ced708baaecd32cb3762c 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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).
index 24dafffc689b80c39face37cfac253d2b686c2f7..e9673020fdb8dbc036505fc95e5985fc6a71476a 100644 (file)
@@ -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
index 87ec4ab41d33f3ca64716755c2a0447239a2087d..2155e73b300897b39f4a1f696be13acab4b5d6ce 100644 (file)
@@ -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()"
index d12400929527a15c4c6d33e47b1a05a407bdc762..1bba3ebf6be17926a44135a2e52a00859a1e463e 100644 (file)
@@ -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
index cae63b06c3eabee1b5745dc64630213bb524db97..17de515410b1d32e999a427d4e125831a3c72567 100644 (file)
@@ -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;
        }
 
@@ -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;
        }
 
index 92b20627e1abf298ca424bb61ab6486a68585dae..faa8f6174bb2defa3a83e60541b71ef40e06cfc8 100644 (file)
@@ -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;
        }
 
index 3a11acbdc89bf8353bebf03ab971c939854f7dba..9454ad2d687713ccfc0b58c03a798a577f4095af 100644 (file)
@@ -2876,12 +2876,13 @@ try_function_name:
                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;
        }
 
@@ -3042,12 +3043,13 @@ try_function_name:
                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;
        }
 
@@ -3155,12 +3157,13 @@ try_function_name:
                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;
        }