Skip to content

Commit 19de727

Browse files
committed
Report magic method names as written
Report the name the way the user has written it, the same way we always do.
1 parent 149029b commit 19de727

File tree

3 files changed

+60
-59
lines changed

3 files changed

+60
-59
lines changed

Zend/tests/magic_methods_006.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ interface a {
99

1010
?>
1111
--EXPECTF--
12-
Fatal error: Method a::__callStatic() must be static in %s on line %d
12+
Fatal error: Method a::__callstatic() must be static in %s on line %d

Zend/tests/magic_methods_009.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class a {
1010

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

Zend/zend_API.c

+58-57
Original file line numberDiff line numberDiff line change
@@ -2008,63 +2008,64 @@ ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *mod
20082008
/* }}} */
20092009

20102010
static void zend_check_magic_method_args(
2011-
uint32_t num_args, const char *name,
2012-
const zend_class_entry *ce, const zend_function *fptr, int error_type)
2011+
uint32_t num_args, const zend_class_entry *ce, const zend_function *fptr, int error_type)
20132012
{
20142013
if (fptr->common.num_args != num_args) {
20152014
if (num_args == 0) {
20162015
zend_error(error_type, "Method %s::%s() cannot take arguments",
2017-
ZSTR_VAL(ce->name), name);
2016+
ZSTR_VAL(ce->name), ZSTR_VAL(fptr->common.function_name));
20182017
} else if (num_args == 1) {
20192018
zend_error(error_type, "Method %s::%s() must take exactly 1 argument",
2020-
ZSTR_VAL(ce->name), name);
2019+
ZSTR_VAL(ce->name), ZSTR_VAL(fptr->common.function_name));
20212020
} else {
20222021
zend_error(error_type, "Method %s::%s() must take exactly %" PRIu32 " arguments",
2023-
ZSTR_VAL(ce->name), name, num_args);
2022+
ZSTR_VAL(ce->name), ZSTR_VAL(fptr->common.function_name), num_args);
20242023
}
20252024
return;
20262025
}
20272026
for (uint32_t i = 0; i < num_args; i++) {
20282027
if (QUICK_ARG_SHOULD_BE_SENT_BY_REF(fptr, i + 1)) {
20292028
zend_error(error_type, "Method %s::%s() cannot take arguments by reference",
2030-
ZSTR_VAL(ce->name), name);
2029+
ZSTR_VAL(ce->name), ZSTR_VAL(fptr->common.function_name));
20312030
return;
20322031
}
20332032
}
20342033
}
20352034

20362035
static void zend_check_magic_method_non_static(
2037-
const char *name, const zend_class_entry *ce, const zend_function *fptr, int error_type)
2036+
const zend_class_entry *ce, const zend_function *fptr, int error_type)
20382037
{
20392038
if (fptr->common.fn_flags & ZEND_ACC_STATIC) {
2040-
zend_error(error_type, "Method %s::%s() cannot be static", ZSTR_VAL(ce->name), name);
2039+
zend_error(error_type, "Method %s::%s() cannot be static",
2040+
ZSTR_VAL(ce->name), ZSTR_VAL(fptr->common.function_name));
20412041
}
20422042
}
20432043

20442044
static void zend_check_magic_method_static(
2045-
const char *name, const zend_class_entry *ce, const zend_function *fptr, int error_type)
2045+
const zend_class_entry *ce, const zend_function *fptr, int error_type)
20462046
{
20472047
if (!(fptr->common.fn_flags & ZEND_ACC_STATIC)) {
2048-
zend_error(error_type, "Method %s::%s() must be static", ZSTR_VAL(ce->name), name);
2048+
zend_error(error_type, "Method %s::%s() must be static",
2049+
ZSTR_VAL(ce->name), ZSTR_VAL(fptr->common.function_name));
20492050
}
20502051
}
20512052

20522053
static void zend_check_magic_method_public(
2053-
const char *name, const zend_class_entry *ce, const zend_function *fptr, int error_type)
2054+
const zend_class_entry *ce, const zend_function *fptr, int error_type)
20542055
{
20552056
// TODO: Remove this warning after adding proper visibility handling.
20562057
if (!(fptr->common.fn_flags & ZEND_ACC_PUBLIC)) {
20572058
zend_error(E_WARNING, "The magic method %s::%s() must have public visibility",
2058-
ZSTR_VAL(ce->name), name);
2059+
ZSTR_VAL(ce->name), ZSTR_VAL(fptr->common.function_name));
20592060
}
20602061
}
20612062

20622063
static void zend_check_magic_method_no_return_type(
2063-
const char *name, const zend_class_entry *ce, const zend_function *fptr, int error_type)
2064+
const zend_class_entry *ce, const zend_function *fptr, int error_type)
20642065
{
20652066
if (fptr->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
20662067
zend_error_noreturn(error_type, "Method %s::%s() cannot declare a return type",
2067-
ZSTR_VAL(ce->name), name);
2068+
ZSTR_VAL(ce->name), ZSTR_VAL(fptr->common.function_name));
20682069
}
20692070
}
20702071

@@ -2076,63 +2077,63 @@ ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce,
20762077
}
20772078

20782079
if (zend_string_equals_literal(lcname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
2079-
zend_check_magic_method_non_static("__construct", ce, fptr, error_type);
2080-
zend_check_magic_method_no_return_type("__construct", ce, fptr, error_type);
2080+
zend_check_magic_method_non_static(ce, fptr, error_type);
2081+
zend_check_magic_method_no_return_type(ce, fptr, error_type);
20812082
} else if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME)) {
2082-
zend_check_magic_method_args(0, "__destruct", ce, fptr, error_type);
2083-
zend_check_magic_method_non_static("__destruct", ce, fptr, error_type);
2084-
zend_check_magic_method_no_return_type("__destruct", ce, fptr, error_type);
2083+
zend_check_magic_method_args(0, ce, fptr, error_type);
2084+
zend_check_magic_method_non_static(ce, fptr, error_type);
2085+
zend_check_magic_method_no_return_type(ce, fptr, error_type);
20852086
} else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
2086-
zend_check_magic_method_args(0, "__clone", ce, fptr, error_type);
2087-
zend_check_magic_method_non_static("__clone", ce, fptr, error_type);
2088-
zend_check_magic_method_no_return_type("__clone", ce, fptr, error_type);
2087+
zend_check_magic_method_args(0, ce, fptr, error_type);
2088+
zend_check_magic_method_non_static(ce, fptr, error_type);
2089+
zend_check_magic_method_no_return_type(ce, fptr, error_type);
20892090
} else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
2090-
zend_check_magic_method_args(1, "__get", ce, fptr, error_type);
2091-
zend_check_magic_method_non_static("__get", ce, fptr, error_type);
2092-
zend_check_magic_method_public("__get", ce, fptr, error_type);
2091+
zend_check_magic_method_args(1, ce, fptr, error_type);
2092+
zend_check_magic_method_non_static(ce, fptr, error_type);
2093+
zend_check_magic_method_public(ce, fptr, error_type);
20932094
} else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
2094-
zend_check_magic_method_args(2, "__set", ce, fptr, error_type);
2095-
zend_check_magic_method_non_static("__set", ce, fptr, error_type);
2096-
zend_check_magic_method_public("__set", ce, fptr, error_type);
2095+
zend_check_magic_method_args(2, ce, fptr, error_type);
2096+
zend_check_magic_method_non_static(ce, fptr, error_type);
2097+
zend_check_magic_method_public(ce, fptr, error_type);
20972098
} else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
2098-
zend_check_magic_method_args(1, "__unset", ce, fptr, error_type);
2099-
zend_check_magic_method_non_static("__unset", ce, fptr, error_type);
2100-
zend_check_magic_method_public("__unset", ce, fptr, error_type);
2099+
zend_check_magic_method_args(1, ce, fptr, error_type);
2100+
zend_check_magic_method_non_static(ce, fptr, error_type);
2101+
zend_check_magic_method_public(ce, fptr, error_type);
21012102
} else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
2102-
zend_check_magic_method_args(1, "__isset", ce, fptr, error_type);
2103-
zend_check_magic_method_non_static("__isset", ce, fptr, error_type);
2104-
zend_check_magic_method_public("__isset", ce, fptr, error_type);
2103+
zend_check_magic_method_args(1, ce, fptr, error_type);
2104+
zend_check_magic_method_non_static(ce, fptr, error_type);
2105+
zend_check_magic_method_public(ce, fptr, error_type);
21052106
} else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
2106-
zend_check_magic_method_args(2, "__call", ce, fptr, error_type);
2107-
zend_check_magic_method_non_static("__call", ce, fptr, error_type);
2108-
zend_check_magic_method_public("__call", ce, fptr, error_type);
2107+
zend_check_magic_method_args(2, ce, fptr, error_type);
2108+
zend_check_magic_method_non_static(ce, fptr, error_type);
2109+
zend_check_magic_method_public(ce, fptr, error_type);
21092110
} else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
2110-
zend_check_magic_method_args(2, "__callStatic", ce, fptr, error_type);
2111-
zend_check_magic_method_static("__callStatic", ce, fptr, error_type);
2112-
zend_check_magic_method_public("__callStatic", ce, fptr, error_type);
2111+
zend_check_magic_method_args(2, ce, fptr, error_type);
2112+
zend_check_magic_method_static(ce, fptr, error_type);
2113+
zend_check_magic_method_public(ce, fptr, error_type);
21132114
} else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
2114-
zend_check_magic_method_args(0, "__toString", ce, fptr, error_type);
2115-
zend_check_magic_method_non_static("__toString", ce, fptr, error_type);
2116-
zend_check_magic_method_public("__toString", ce, fptr, error_type);
2115+
zend_check_magic_method_args(0, ce, fptr, error_type);
2116+
zend_check_magic_method_non_static(ce, fptr, error_type);
2117+
zend_check_magic_method_public(ce, fptr, error_type);
21172118
} else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
2118-
zend_check_magic_method_args(0, "__debugInfo", ce, fptr, error_type);
2119-
zend_check_magic_method_non_static("__debugInfo", ce, fptr, error_type);
2120-
zend_check_magic_method_public("__debugInfo", ce, fptr, error_type);
2119+
zend_check_magic_method_args(0, ce, fptr, error_type);
2120+
zend_check_magic_method_non_static(ce, fptr, error_type);
2121+
zend_check_magic_method_public(ce, fptr, error_type);
21212122
} else if (zend_string_equals_literal(lcname, "__serialize")) {
2122-
zend_check_magic_method_args(0, "__serialize", ce, fptr, error_type);
2123-
zend_check_magic_method_non_static("__serialize", ce, fptr, error_type);
2124-
zend_check_magic_method_public("__serialize", ce, fptr, error_type);
2123+
zend_check_magic_method_args(0, ce, fptr, error_type);
2124+
zend_check_magic_method_non_static(ce, fptr, error_type);
2125+
zend_check_magic_method_public(ce, fptr, error_type);
21252126
} else if (zend_string_equals_literal(lcname, "__unserialize")) {
2126-
zend_check_magic_method_args(1, "__unserialize", ce, fptr, error_type);
2127-
zend_check_magic_method_non_static("__unserialize", ce, fptr, error_type);
2128-
zend_check_magic_method_public("__unserialize", ce, fptr, error_type);
2127+
zend_check_magic_method_args(1, ce, fptr, error_type);
2128+
zend_check_magic_method_non_static(ce, fptr, error_type);
2129+
zend_check_magic_method_public(ce, fptr, error_type);
21292130
} else if (zend_string_equals_literal(lcname, "__set_state")) {
2130-
zend_check_magic_method_args(1, "__set_state", ce, fptr, error_type);
2131-
zend_check_magic_method_static("__set_state", ce, fptr, error_type);
2132-
zend_check_magic_method_public("__set_state", ce, fptr, error_type);
2131+
zend_check_magic_method_args(1, ce, fptr, error_type);
2132+
zend_check_magic_method_static(ce, fptr, error_type);
2133+
zend_check_magic_method_public(ce, fptr, error_type);
21332134
} else if (zend_string_equals_literal(lcname, "__invoke")) {
2134-
zend_check_magic_method_non_static("__invoke", ce, fptr, error_type);
2135-
zend_check_magic_method_public("__invoke", ce, fptr, error_type);
2135+
zend_check_magic_method_non_static(ce, fptr, error_type);
2136+
zend_check_magic_method_public(ce, fptr, error_type);
21362137
}
21372138
}
21382139
/* }}} */

0 commit comments

Comments
 (0)