Skip to content

Split error messages while checking magic methods attributes #5465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Zend/tests/bug61025.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ echo $b->__invoke();

?>
--EXPECTF--
Warning: The magic method InvokeAble::__invoke() must have public visibility and cannot be static in %sbug61025.php on line %d
Warning: The magic method InvokeAble::__invoke() 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
Warning: The magic method Bar::__invoke() must have public visibility 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:
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug65322.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ eval('class A { private function __invoke() { } }');

?>
--EXPECTF--
string(%d) "The magic method A::__invoke() must have public visibility and cannot be static"
string(%d) "The magic method A::__invoke() must have public visibility"
string(%d) "%s(%d) : eval()'d code"
string(1) "X"
2 changes: 1 addition & 1 deletion Zend/tests/bug67436/bug67436.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ a::staticTest();
$b = new b();
$b->test();
--EXPECTF--
string(%d) "The magic method b::__invoke() must have public visibility and cannot be static"
string(%d) "The magic method b::__invoke() must have public visibility"
b::test()
a::test(c::TESTCONSTANT)
2 changes: 1 addition & 1 deletion Zend/tests/bug67436/bug67436_nohandler.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ a::staticTest();
$b = new b();
$b->test();
--EXPECTF--
Warning: The magic method b::__invoke() must have public visibility and cannot be static in %s on line %d
Warning: The magic method b::__invoke() must have public visibility in %s on line %d
b::test()
a::test(c::TESTCONSTANT)
2 changes: 1 addition & 1 deletion Zend/tests/bug70215.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ $b();

?>
--EXPECTF--
Warning: The magic method A::__invoke() must have public visibility and cannot be static in %s on line %d
Warning: The magic method A::__invoke() cannot be static in %s on line %d
A
2 changes: 1 addition & 1 deletion Zend/tests/errmsg_045.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ eval('class A { private function __invoke() { } }');

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

Warning: Undefined variable $undefined in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/magic_methods_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class foo {

?>
--EXPECTF--
Warning: The magic method foo::__unset() must have public visibility and cannot be static in %s on line %d
Warning: The magic method foo::__unset() must have public visibility in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/magic_methods_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class foo {

?>
--EXPECTF--
Warning: The magic method foo::__unset() must have public visibility and cannot be static in %s on line %d
Warning: The magic method foo::__unset() cannot be static in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/magic_methods_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ class foo {

?>
--EXPECTF--
Warning: The magic method foo::__unset() must have public visibility and cannot be static in %s on line %d
Warning: The magic method foo::__unset() must have public visibility in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/magic_methods_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ interface a {

?>
--EXPECTF--
Warning: The magic method a::__call() must have public visibility and cannot be static in %s on line %d
Warning: The magic method a::__call() cannot be static in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/magic_methods_006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ interface a {

?>
--EXPECTF--
Warning: The magic method a::__callStatic() must have public visibility and be static in %s on line %d
Warning: The magic method a::__callStatic() must be static in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/magic_methods_007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ abstract class b {

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

Fatal error: Method b::__set() must take exactly 2 arguments in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/magic_methods_008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class a extends b {

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

Fatal error: Access level to a::__set() must be public (as in class b) in %s on line 8
2 changes: 1 addition & 1 deletion Zend/tests/magic_methods_009.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ class a {

?>
--EXPECTF--
Warning: The magic method a::__callStatic() must have public visibility and be static in %s on line %d
Warning: The magic method a::__callStatic() must have public visibility in %s on line %d
4 changes: 3 additions & 1 deletion Zend/tests/magic_methods_010.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class a {

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

Warning: The magic method a::__toString() cannot be static in %s on line %d

Fatal error: Method a::__toString() cannot take arguments in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/magic_methods_serialize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class Foo {
}
?>
--EXPECTF--
Warning: The magic method Foo::__serialize() must have public visibility and cannot be static in %s on line %d
Warning: The magic method Foo::__serialize() cannot be static in %s on line %d

Fatal error: Method Foo::__serialize() cannot take arguments in %s on line %d
2 changes: 1 addition & 1 deletion Zend/tests/magic_methods_unserialize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class Foo {
}
?>
--EXPECTF--
Warning: The magic method Foo::__unserialize() must have public visibility and cannot be static in %s on line %d
Warning: The magic method Foo::__unserialize() cannot be static in %s on line %d

Fatal error: Method Foo::__unserialize() must take exactly 1 argument in %s on line %d
14 changes: 10 additions & 4 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -6052,15 +6052,21 @@ static void zend_compile_implicit_closure_uses(closure_info *info)

static void zend_check_magic_method_attr(uint32_t attr, zend_class_entry *ce, const char* method, zend_bool is_static) /* {{{ */
{
if (!(attr & ZEND_ACC_PUBLIC)) {
zend_error(E_WARNING,
"The magic method %s::%s() must have public visibility",
ZSTR_VAL(ce->name), method);
}

if (is_static) {
if (!(attr & ZEND_ACC_PUBLIC) || !(attr & ZEND_ACC_STATIC)) {
if (!(attr & ZEND_ACC_STATIC)) {
zend_error(E_WARNING,
"The magic method %s::%s() must have public visibility and be static",
"The magic method %s::%s() must be static",
ZSTR_VAL(ce->name), method);
}
} else if (!(attr & ZEND_ACC_PUBLIC) || (attr & ZEND_ACC_STATIC)) {
} else if (attr & ZEND_ACC_STATIC) {
zend_error(E_WARNING,
"The magic method %s::%s() must have public visibility and cannot be static",
"The magic method %s::%s() cannot be static",
ZSTR_VAL(ce->name), method);
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/classes/__call_005.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $b = new B();
$b->test();
?>
--EXPECTF--
Warning: The magic method A::__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 in %s__call_005.php on line 3
In A::__call(test1, array(1,a))
object(B)#1 (0) {
}
Expand Down
2 changes: 1 addition & 1 deletion tests/classes/__call_007.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ try {
}
?>
--EXPECTF--
Warning: The magic method A::__call() must have public visibility and cannot be static in %s on line 3
Warning: The magic method A::__call() cannot be static in %s on line 3
---> Invoke __call via simple method call.
object(A)#1 (0) {
}
Expand Down