Skip to content

Commit 75a58ba

Browse files
committed
Improve error messages for magic methods by appending method's class
Closes GH-5397.
1 parent 481caf1 commit 75a58ba

18 files changed

+34
-32
lines changed

Zend/tests/bug61025.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ echo $b->__invoke();
2020

2121
?>
2222
--EXPECTF--
23-
Warning: The magic method __invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
23+
Warning: The magic method InvokeAble::__invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
2424

25-
Warning: The magic method __invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
25+
Warning: The magic method Bar::__invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
2626
Bar
2727
Fatal error: Uncaught Error: Call to private method Bar::__invoke() from context '' in %sbug61025.php:%d
2828
Stack trace:

Zend/tests/bug65322.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ eval('class A { private function __invoke() { } }');
1919

2020
?>
2121
--EXPECTF--
22-
string(76) "The magic method __invoke() must have public visibility and cannot be static"
22+
string(%d) "The magic method A::__invoke() must have public visibility and cannot be static"
2323
string(%d) "%s(%d) : eval()'d code"
2424
string(1) "X"

Zend/tests/bug67436/bug67436.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ a::staticTest();
2121

2222
$b = new b();
2323
$b->test();
24-
--EXPECT--
25-
string(76) "The magic method __invoke() must have public visibility and cannot be static"
24+
--EXPECTF--
25+
string(%d) "The magic method b::__invoke() must have public visibility and cannot be static"
2626
b::test()
2727
a::test(c::TESTCONSTANT)

Zend/tests/bug67436/bug67436_nohandler.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ a::staticTest();
1414
$b = new b();
1515
$b->test();
1616
--EXPECTF--
17-
Warning: The magic method __invoke() must have public visibility and cannot be static in %s on line %d
17+
Warning: The magic method b::__invoke() must have public visibility and cannot be static in %s on line %d
1818
b::test()
1919
a::test(c::TESTCONSTANT)

Zend/tests/bug70215.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ $b();
1717

1818
?>
1919
--EXPECTF--
20-
Warning: The magic method __invoke() must have public visibility and cannot be static in %s on line %d
20+
Warning: The magic method A::__invoke() must have public visibility and cannot be static in %s on line %d
2121
A

Zend/tests/errmsg_045.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ eval('class A { private function __invoke() { } }');
1414

1515
?>
1616
--EXPECTF--
17-
string(76) "The magic method __invoke() must have public visibility and cannot be static"
17+
string(%d) "The magic method A::__invoke() must have public visibility and cannot be static"
1818
string(%d) "%s(%d) : eval()'d code"
1919

2020
Warning: Undefined variable $undefined in %s on line %d

Zend/tests/magic_methods_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class foo {
1111

1212
?>
1313
--EXPECTF--
14-
Warning: The magic method __unset() must have public visibility and cannot be static in %s on line %d
14+
Warning: The magic method foo::__unset() must have public visibility and cannot be static in %s on line %d

Zend/tests/magic_methods_003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class foo {
1111

1212
?>
1313
--EXPECTF--
14-
Warning: The magic method __unset() must have public visibility and cannot be static in %s on line %d
14+
Warning: The magic method foo::__unset() must have public visibility and cannot be static in %s on line %d

Zend/tests/magic_methods_004.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ class foo {
1111

1212
?>
1313
--EXPECTF--
14-
Warning: The magic method __unset() must have public visibility and cannot be static in %s on line %d
14+
Warning: The magic method foo::__unset() must have public visibility and cannot be static in %s on line %d

Zend/tests/magic_methods_005.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ interface a {
99

1010
?>
1111
--EXPECTF--
12-
Warning: The magic method __call() must have public visibility and cannot be static in %s on line %d
12+
Warning: The magic method a::__call() must have public visibility and cannot be static in %s on line %d

Zend/tests/magic_methods_006.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ interface a {
99

1010
?>
1111
--EXPECTF--
12-
Warning: The magic method __callStatic() must have public visibility and be static in %s on line %d
12+
Warning: The magic method a::__callStatic() must have public visibility and be static in %s on line %d

Zend/tests/magic_methods_007.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ abstract class b {
99

1010
?>
1111
--EXPECTF--
12-
Warning: The magic method __set() must have public visibility and cannot be static in %s on line %d
12+
Warning: The magic method b::__set() must have public visibility and cannot be static in %s on line %d
1313

1414
Fatal error: Method b::__set() must take exactly 2 arguments in %s on line %d

Zend/tests/magic_methods_008.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ class a extends b {
1414

1515
?>
1616
--EXPECTF--
17-
Warning: The magic method __set() must have public visibility and cannot be static in %s on line %d
17+
Warning: The magic method a::__set() must have public visibility and cannot be static in %s on line %d
1818

1919
Fatal error: Access level to a::__set() must be public (as in class b) in %s on line 8

Zend/tests/magic_methods_009.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class a {
1010

1111
?>
1212
--EXPECTF--
13-
Warning: The magic method __callStatic() must have public visibility and be static in %s on line %d
13+
Warning: The magic method a::__callStatic() must have public visibility and be static in %s on line %d

Zend/tests/magic_methods_010.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class a {
1010

1111
?>
1212
--EXPECTF--
13-
Warning: The magic method __toString() must have public visibility and cannot be static in %s on line %d
13+
Warning: The magic method a::__toString() must have public visibility and cannot be static in %s on line %d
1414

1515
Fatal error: Method a::__tostring() cannot take arguments in %s on line %d

Zend/zend_compile.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6049,16 +6049,18 @@ static void zend_compile_implicit_closure_uses(closure_info *info)
60496049
ZEND_HASH_FOREACH_END();
60506050
}
60516051

6052-
static void zend_check_magic_method_attr(uint32_t attr, const char* method, zend_bool is_static) /* {{{ */
6052+
static void zend_check_magic_method_attr(uint32_t attr, zend_class_entry *ce, const char* method, zend_bool is_static) /* {{{ */
60536053
{
60546054
if (is_static) {
60556055
if (!(attr & ZEND_ACC_PUBLIC) || !(attr & ZEND_ACC_STATIC)) {
6056-
zend_error(E_WARNING, "The magic method %s() must have public visibility and be static", method);
6056+
zend_error(E_WARNING,
6057+
"The magic method %s::%s() must have public visibility and be static",
6058+
ZSTR_VAL(ce->name), method);
60576059
}
60586060
} else if (!(attr & ZEND_ACC_PUBLIC) || (attr & ZEND_ACC_STATIC)) {
60596061
zend_error(E_WARNING,
6060-
"The magic method %s() must have public visibility and cannot be static",
6061-
method);
6062+
"The magic method %s::%s() must have public visibility and cannot be static",
6063+
ZSTR_VAL(ce->name), method);
60626064
}
60636065
}
60646066
/* }}} */
@@ -6138,35 +6140,35 @@ void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_boo
61386140
} else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
61396141
ce->clone = (zend_function *) op_array;
61406142
} else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
6141-
zend_check_magic_method_attr(fn_flags, "__call", 0);
6143+
zend_check_magic_method_attr(fn_flags, ce, "__call", 0);
61426144
ce->__call = (zend_function *) op_array;
61436145
} else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
6144-
zend_check_magic_method_attr(fn_flags, "__callStatic", 1);
6146+
zend_check_magic_method_attr(fn_flags, ce, "__callStatic", 1);
61456147
ce->__callstatic = (zend_function *) op_array;
61466148
} else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
6147-
zend_check_magic_method_attr(fn_flags, "__get", 0);
6149+
zend_check_magic_method_attr(fn_flags, ce, "__get", 0);
61486150
ce->__get = (zend_function *) op_array;
61496151
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
61506152
} else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
6151-
zend_check_magic_method_attr(fn_flags, "__set", 0);
6153+
zend_check_magic_method_attr(fn_flags, ce, "__set", 0);
61526154
ce->__set = (zend_function *) op_array;
61536155
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
61546156
} else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
6155-
zend_check_magic_method_attr(fn_flags, "__unset", 0);
6157+
zend_check_magic_method_attr(fn_flags, ce, "__unset", 0);
61566158
ce->__unset = (zend_function *) op_array;
61576159
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
61586160
} else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
6159-
zend_check_magic_method_attr(fn_flags, "__isset", 0);
6161+
zend_check_magic_method_attr(fn_flags, ce, "__unset", 0);
61606162
ce->__isset = (zend_function *) op_array;
61616163
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
61626164
} else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
6163-
zend_check_magic_method_attr(fn_flags, "__toString", 0);
6165+
zend_check_magic_method_attr(fn_flags, ce, "__toString", 0);
61646166
ce->__tostring = (zend_function *) op_array;
61656167
add_stringable_interface(ce);
61666168
} else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
6167-
zend_check_magic_method_attr(fn_flags, "__invoke", 0);
6169+
zend_check_magic_method_attr(fn_flags, ce, "__invoke", 0);
61686170
} else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
6169-
zend_check_magic_method_attr(fn_flags, "__debugInfo", 0);
6171+
zend_check_magic_method_attr(fn_flags, ce, "__debugInfo", 0);
61706172
ce->__debugInfo = (zend_function *) op_array;
61716173
}
61726174

tests/classes/__call_005.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $b = new B();
2222
$b->test();
2323
?>
2424
--EXPECTF--
25-
Warning: The magic method __call() must have public visibility and cannot be static in %s__call_005.php on line 3
25+
Warning: The magic method A::__call() must have public visibility and cannot be static in %s__call_005.php on line 3
2626
In A::__call(test1, array(1,a))
2727
object(B)#1 (0) {
2828
}

tests/classes/__call_007.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ try {
5151
}
5252
?>
5353
--EXPECTF--
54-
Warning: The magic method __call() must have public visibility and cannot be static in %s on line 3
54+
Warning: The magic method A::__call() must have public visibility and cannot be static in %s on line 3
5555
---> Invoke __call via simple method call.
5656
object(A)#1 (0) {
5757
}

0 commit comments

Comments
 (0)