]> granicus.if.org Git - php/commitdiff
Improve error messages for magic methods by appending method's class
authorGabriel Caruso <carusogabriel34@gmail.com>
Wed, 15 Apr 2020 23:39:51 +0000 (01:39 +0200)
committerGabriel Caruso <carusogabriel34@gmail.com>
Thu, 16 Apr 2020 08:34:58 +0000 (10:34 +0200)
Closes GH-5397.

18 files changed:
Zend/tests/bug61025.phpt
Zend/tests/bug65322.phpt
Zend/tests/bug67436/bug67436.phpt
Zend/tests/bug67436/bug67436_nohandler.phpt
Zend/tests/bug70215.phpt
Zend/tests/errmsg_045.phpt
Zend/tests/magic_methods_002.phpt
Zend/tests/magic_methods_003.phpt
Zend/tests/magic_methods_004.phpt
Zend/tests/magic_methods_005.phpt
Zend/tests/magic_methods_006.phpt
Zend/tests/magic_methods_007.phpt
Zend/tests/magic_methods_008.phpt
Zend/tests/magic_methods_009.phpt
Zend/tests/magic_methods_010.phpt
Zend/zend_compile.c
tests/classes/__call_005.phpt
tests/classes/__call_007.phpt

index f6731535fb2a3430f9b74895f97552f1276553f8..54f6443f85c806a9b1cf898f36c3bee28ca5f3ee 100644 (file)
@@ -20,9 +20,9 @@ echo $b->__invoke();
 
 ?>
 --EXPECTF--
-Warning: The magic method __invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
+Warning: The magic method InvokeAble::__invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
 
-Warning: The magic method __invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
+Warning: The magic method Bar::__invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
 Bar
 Fatal error: Uncaught Error: Call to private method Bar::__invoke() from context '' in %sbug61025.php:%d
 Stack trace:
index 2ae2780bb628d388e3c43323f03f54ca4a76cead..9b5da8e4b7fa499826b82323adf207390d056cdf 100644 (file)
@@ -19,6 +19,6 @@ eval('class A { private function __invoke() { } }');
 
 ?>
 --EXPECTF--
-string(76) "The magic method __invoke() must have public visibility and cannot be static"
+string(%d) "The magic method A::__invoke() must have public visibility and cannot be static"
 string(%d) "%s(%d) : eval()'d code"
 string(1) "X"
index 0d8ec870062ed420a036d10496b57852fb4981f1..ade29731ae4e48fae792e3f5b13d9506c0574f47 100644 (file)
@@ -21,7 +21,7 @@ a::staticTest();
 
 $b = new b();
 $b->test();
---EXPECT--
-string(76) "The magic method __invoke() must have public visibility and cannot be static"
+--EXPECTF--
+string(%d) "The magic method b::__invoke() must have public visibility and cannot be static"
 b::test()
 a::test(c::TESTCONSTANT)
index 64c7f706421ad79088fbd31cb6c3f115dd501bee..abccfb62f49230df6b419f10a0190515bd156cc0 100644 (file)
@@ -14,6 +14,6 @@ a::staticTest();
 $b = new b();
 $b->test();
 --EXPECTF--
-Warning: The magic method __invoke() must have public visibility and cannot be static in %s on line %d
+Warning: The magic method b::__invoke() must have public visibility and cannot be static in %s on line %d
 b::test()
 a::test(c::TESTCONSTANT)
index 851a6b855ed20e5f5e7921d92830dda2d4bd09a0..76a96722251a059f7a8322109030208810eff21e 100644 (file)
@@ -17,5 +17,5 @@ $b();
 
 ?>
 --EXPECTF--
-Warning: The magic method __invoke() must have public visibility and cannot be static in %s on line %d
+Warning: The magic method A::__invoke() must have public visibility and cannot be static in %s on line %d
 A
index 172f56f26b9cf7dc727c3adc44685431e92cc225..35e6c7b00fef0355948b059aeeff065e80455356 100644 (file)
@@ -14,7 +14,7 @@ eval('class A { private function __invoke() { } }');
 
 ?>
 --EXPECTF--
-string(76) "The magic method __invoke() must have public visibility and cannot be static"
+string(%d) "The magic method A::__invoke() must have public visibility and cannot be static"
 string(%d) "%s(%d) : eval()'d code"
 
 Warning: Undefined variable $undefined in %s on line %d
index fdbb97be409502ad2efafde2a53ab3748544a943..dbd4977ad6fe95494d470004425e6881689e2acf 100644 (file)
@@ -11,4 +11,4 @@ class foo {
 
 ?>
 --EXPECTF--
-Warning: The magic method __unset() must have public visibility and cannot be static in %s on line %d
+Warning: The magic method foo::__unset() must have public visibility and cannot be static in %s on line %d
index cd96d15b2fae121f76bbd7aa299dccc675511ad4..d2207e9db76cf89d284b282559d23c613e170dee 100644 (file)
@@ -11,4 +11,4 @@ class foo {
 
 ?>
 --EXPECTF--
-Warning: The magic method __unset() must have public visibility and cannot be static in %s on line %d
+Warning: The magic method foo::__unset() must have public visibility and cannot be static in %s on line %d
index 3c1df73d095b34be1212834e1c70bb76241b76d3..695747fdc72bb0ed563367e21be6679a4cd470a0 100644 (file)
@@ -11,4 +11,4 @@ class foo {
 
 ?>
 --EXPECTF--
-Warning: The magic method __unset() must have public visibility and cannot be static in %s on line %d
+Warning: The magic method foo::__unset() must have public visibility and cannot be static in %s on line %d
index 8e7749381ca276c81ed373276859f1189cbd80cf..14704c9229fc8e67f05a921609cfe912c4e57657 100644 (file)
@@ -9,4 +9,4 @@ interface a {
 
 ?>
 --EXPECTF--
-Warning: The magic method __call() must have public visibility and cannot be static in %s on line %d
+Warning: The magic method a::__call() must have public visibility and cannot be static in %s on line %d
index 68eac7439d6f05d52bdad5035ebfd81a45c62e00..92c01636ce162ba1cff346750a4b769a95a1d2b9 100644 (file)
@@ -9,4 +9,4 @@ interface a {
 
 ?>
 --EXPECTF--
-Warning: The magic method __callStatic() must have public visibility and be static in %s on line %d
+Warning: The magic method a::__callStatic() must have public visibility and be static in %s on line %d
index 63f4cadff574d31a3329ce553a3c388312408f83..dd7714e5df1d0e4c09b82291f990cc48954af458 100644 (file)
@@ -9,6 +9,6 @@ abstract class b {
 
 ?>
 --EXPECTF--
-Warning: The magic method __set() must have public visibility and cannot be static in %s on line %d
+Warning: The magic method b::__set() must have public visibility and cannot be static in %s on line %d
 
 Fatal error: Method b::__set() must take exactly 2 arguments in %s on line %d
index 7d7a839afe82e144fe2d85c00a9f74d001892cf4..de99ecafd9e3dd3a42905d13c7979b7787c1492c 100644 (file)
@@ -14,6 +14,6 @@ class a extends b {
 
 ?>
 --EXPECTF--
-Warning: The magic method __set() must have public visibility and cannot be static in %s on line %d
+Warning: The magic method a::__set() must have public visibility and cannot be static in %s on line %d
 
 Fatal error: Access level to a::__set() must be public (as in class b) in %s on line 8
index ff609ce4523c40da28bee1be6c908ff9a96bc6a9..17a99cef48616d60a5bae47029e2aa65fcaed244 100644 (file)
@@ -10,4 +10,4 @@ class a {
 
 ?>
 --EXPECTF--
-Warning: The magic method __callStatic() must have public visibility and be static in %s on line %d
+Warning: The magic method a::__callStatic() must have public visibility and be static in %s on line %d
index 8ec3f23e614d1434d5b96b03a5a03a8fc15beee6..6118bda67b56e5362a9ff5774bad02bcf73f8f2f 100644 (file)
@@ -10,6 +10,6 @@ class a {
 
 ?>
 --EXPECTF--
-Warning: The magic method __toString() must have public visibility and cannot be static in %s on line %d
+Warning: The magic method a::__toString() must have public visibility and cannot be static in %s on line %d
 
 Fatal error: Method a::__tostring() cannot take arguments in %s on line %d
index 953bf6dfd59eb2431f21817440968823bafc9d4c..9d186b30fdcf8e6c60d4fecbd92de1d30015d0e8 100644 (file)
@@ -6049,16 +6049,18 @@ static void zend_compile_implicit_closure_uses(closure_info *info)
        ZEND_HASH_FOREACH_END();
 }
 
-static void zend_check_magic_method_attr(uint32_t attr, const char* method, zend_bool is_static) /* {{{ */
+static void zend_check_magic_method_attr(uint32_t attr, zend_class_entry *ce, const char* method, zend_bool is_static) /* {{{ */
 {
        if (is_static) {
                if (!(attr & ZEND_ACC_PUBLIC) || !(attr & ZEND_ACC_STATIC)) {
-                       zend_error(E_WARNING, "The magic method %s() must have public visibility and be static", method);
+                       zend_error(E_WARNING,
+                               "The magic method %s::%s() must have public visibility and be static",
+                               ZSTR_VAL(ce->name), method);
                }
        } else if (!(attr & ZEND_ACC_PUBLIC) || (attr & ZEND_ACC_STATIC)) {
                zend_error(E_WARNING,
-                               "The magic method %s() must have public visibility and cannot be static",
-                               method);
+                               "The magic method %s::%s() must have public visibility and cannot be static",
+                               ZSTR_VAL(ce->name), method);
        }
 }
 /* }}} */
@@ -6138,35 +6140,35 @@ void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_boo
        } else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
                ce->clone = (zend_function *) op_array;
        } else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__call", 0);
+               zend_check_magic_method_attr(fn_flags, ce, "__call", 0);
                ce->__call = (zend_function *) op_array;
        } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__callStatic", 1);
+               zend_check_magic_method_attr(fn_flags, ce, "__callStatic", 1);
                ce->__callstatic = (zend_function *) op_array;
        } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__get", 0);
+               zend_check_magic_method_attr(fn_flags, ce, "__get", 0);
                ce->__get = (zend_function *) op_array;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
        } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__set", 0);
+               zend_check_magic_method_attr(fn_flags, ce, "__set", 0);
                ce->__set = (zend_function *) op_array;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
        } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__unset", 0);
+               zend_check_magic_method_attr(fn_flags, ce, "__unset", 0);
                ce->__unset = (zend_function *) op_array;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
        } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__isset", 0);
+               zend_check_magic_method_attr(fn_flags, ce, "__unset", 0);
                ce->__isset = (zend_function *) op_array;
                ce->ce_flags |= ZEND_ACC_USE_GUARDS;
        } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__toString", 0);
+               zend_check_magic_method_attr(fn_flags, ce, "__toString", 0);
                ce->__tostring = (zend_function *) op_array;
                add_stringable_interface(ce);
        } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__invoke", 0);
+               zend_check_magic_method_attr(fn_flags, ce, "__invoke", 0);
        } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
-               zend_check_magic_method_attr(fn_flags, "__debugInfo", 0);
+               zend_check_magic_method_attr(fn_flags, ce, "__debugInfo", 0);
                ce->__debugInfo = (zend_function *) op_array;
        }
 
index 8c4d52efa7850fc0dc663a266a5a6b9f2b00bd44..8db8cec43e3dd6805788da3e9582d680b6f95e03 100644 (file)
@@ -22,7 +22,7 @@ $b = new B();
 $b->test();
 ?>
 --EXPECTF--
-Warning: The magic method __call() must have public visibility and cannot be static in %s__call_005.php on line 3
+Warning: The magic method A::__call() must have public visibility and cannot be static in %s__call_005.php on line 3
 In A::__call(test1, array(1,a))
 object(B)#1 (0) {
 }
index 26dd8e29b60e46e01a9afaa58c73639bf51d7358..6f90e84f7db62911825a3e7651635ed224562e2a 100644 (file)
@@ -51,7 +51,7 @@ try {
 }
 ?>
 --EXPECTF--
-Warning: The magic method __call() must have public visibility and cannot be static in %s on line 3
+Warning: The magic method A::__call() must have public visibility and cannot be static in %s on line 3
 ---> Invoke __call via simple method call.
 object(A)#1 (0) {
 }