mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Improve error messages for magic methods by appending method's class
Closes GH-5397.
This commit is contained in:
parent
481caf17bc
commit
75a58ba522
18 changed files with 34 additions and 32 deletions
|
@ -20,9 +20,9 @@ echo $b->__invoke();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
Bar
|
||||||
Fatal error: Uncaught Error: Call to private method Bar::__invoke() from context '' in %sbug61025.php:%d
|
Fatal error: Uncaught Error: Call to private method Bar::__invoke() from context '' in %sbug61025.php:%d
|
||||||
Stack trace:
|
Stack trace:
|
||||||
|
|
|
@ -19,6 +19,6 @@ eval('class A { private function __invoke() { } }');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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(%d) "%s(%d) : eval()'d code"
|
||||||
string(1) "X"
|
string(1) "X"
|
||||||
|
|
|
@ -21,7 +21,7 @@ a::staticTest();
|
||||||
|
|
||||||
$b = new b();
|
$b = new b();
|
||||||
$b->test();
|
$b->test();
|
||||||
--EXPECT--
|
--EXPECTF--
|
||||||
string(76) "The magic method __invoke() must have public visibility and cannot be static"
|
string(%d) "The magic method b::__invoke() must have public visibility and cannot be static"
|
||||||
b::test()
|
b::test()
|
||||||
a::test(c::TESTCONSTANT)
|
a::test(c::TESTCONSTANT)
|
||||||
|
|
|
@ -14,6 +14,6 @@ a::staticTest();
|
||||||
$b = new b();
|
$b = new b();
|
||||||
$b->test();
|
$b->test();
|
||||||
--EXPECTF--
|
--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()
|
b::test()
|
||||||
a::test(c::TESTCONSTANT)
|
a::test(c::TESTCONSTANT)
|
||||||
|
|
|
@ -17,5 +17,5 @@ $b();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
A
|
||||||
|
|
|
@ -14,7 +14,7 @@ eval('class A { private function __invoke() { } }');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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(%d) "%s(%d) : eval()'d code"
|
||||||
|
|
||||||
Warning: Undefined variable $undefined in %s on line %d
|
Warning: Undefined variable $undefined in %s on line %d
|
||||||
|
|
|
@ -11,4 +11,4 @@ class foo {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
||||||
|
|
|
@ -11,4 +11,4 @@ class foo {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
||||||
|
|
|
@ -11,4 +11,4 @@ class foo {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
||||||
|
|
|
@ -9,4 +9,4 @@ interface a {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
||||||
|
|
|
@ -9,4 +9,4 @@ interface a {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
||||||
|
|
|
@ -9,6 +9,6 @@ abstract class b {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
Fatal error: Method b::__set() must take exactly 2 arguments in %s on line %d
|
||||||
|
|
|
@ -14,6 +14,6 @@ class a extends b {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
Fatal error: Access level to a::__set() must be public (as in class b) in %s on line 8
|
||||||
|
|
|
@ -10,4 +10,4 @@ class a {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
||||||
|
|
|
@ -10,6 +10,6 @@ class a {
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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
|
Fatal error: Method a::__tostring() cannot take arguments in %s on line %d
|
||||||
|
|
|
@ -6049,16 +6049,18 @@ static void zend_compile_implicit_closure_uses(closure_info *info)
|
||||||
ZEND_HASH_FOREACH_END();
|
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 (is_static) {
|
||||||
if (!(attr & ZEND_ACC_PUBLIC) || !(attr & ZEND_ACC_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)) {
|
} else if (!(attr & ZEND_ACC_PUBLIC) || (attr & ZEND_ACC_STATIC)) {
|
||||||
zend_error(E_WARNING,
|
zend_error(E_WARNING,
|
||||||
"The magic method %s() must have public visibility and cannot be static",
|
"The magic method %s::%s() must have public visibility and cannot be static",
|
||||||
method);
|
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)) {
|
} else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
|
||||||
ce->clone = (zend_function *) op_array;
|
ce->clone = (zend_function *) op_array;
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
|
} 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;
|
ce->__call = (zend_function *) op_array;
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
|
} 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;
|
ce->__callstatic = (zend_function *) op_array;
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
|
} 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->__get = (zend_function *) op_array;
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
|
} 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->__set = (zend_function *) op_array;
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
|
} 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->__unset = (zend_function *) op_array;
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
|
} 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->__isset = (zend_function *) op_array;
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
|
} 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;
|
ce->__tostring = (zend_function *) op_array;
|
||||||
add_stringable_interface(ce);
|
add_stringable_interface(ce);
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
|
} 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)) {
|
} 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;
|
ce->__debugInfo = (zend_function *) op_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ $b = new B();
|
||||||
$b->test();
|
$b->test();
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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))
|
In A::__call(test1, array(1,a))
|
||||||
object(B)#1 (0) {
|
object(B)#1 (0) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ try {
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--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.
|
---> Invoke __call via simple method call.
|
||||||
object(A)#1 (0) {
|
object(A)#1 (0) {
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue