@@ -2049,6 +2049,16 @@ static void zend_check_magic_method_static(
2049
2049
}
2050
2050
}
2051
2051
2052
+ static void zend_check_magic_method_public (
2053
+ const char * name , const zend_class_entry * ce , const zend_function * fptr , int error_type )
2054
+ {
2055
+ // TODO: Remove this warning after adding proper visibility handling.
2056
+ if (!(fptr -> common .fn_flags & ZEND_ACC_PUBLIC )) {
2057
+ zend_error (E_WARNING , "The magic method %s::%s() must have public visibility" ,
2058
+ ZSTR_VAL (ce -> name ), name );
2059
+ }
2060
+ }
2061
+
2052
2062
static void zend_check_magic_method_no_return_type (
2053
2063
const char * name , const zend_class_entry * ce , const zend_function * fptr , int error_type )
2054
2064
{
@@ -2079,38 +2089,50 @@ ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce,
2079
2089
} else if (zend_string_equals_literal (lcname , ZEND_GET_FUNC_NAME )) {
2080
2090
zend_check_magic_method_args (1 , "__get" , ce , fptr , error_type );
2081
2091
zend_check_magic_method_non_static ("__get" , ce , fptr , error_type );
2092
+ zend_check_magic_method_public ("__get" , ce , fptr , error_type );
2082
2093
} else if (zend_string_equals_literal (lcname , ZEND_SET_FUNC_NAME )) {
2083
2094
zend_check_magic_method_args (2 , "__set" , ce , fptr , error_type );
2084
2095
zend_check_magic_method_non_static ("__set" , ce , fptr , error_type );
2096
+ zend_check_magic_method_public ("__set" , ce , fptr , error_type );
2085
2097
} else if (zend_string_equals_literal (lcname , ZEND_UNSET_FUNC_NAME )) {
2086
2098
zend_check_magic_method_args (1 , "__unset" , ce , fptr , error_type );
2087
2099
zend_check_magic_method_non_static ("__unset" , ce , fptr , error_type );
2100
+ zend_check_magic_method_public ("__unset" , ce , fptr , error_type );
2088
2101
} else if (zend_string_equals_literal (lcname , ZEND_ISSET_FUNC_NAME )) {
2089
2102
zend_check_magic_method_args (1 , "__isset" , ce , fptr , error_type );
2090
2103
zend_check_magic_method_non_static ("__isset" , ce , fptr , error_type );
2104
+ zend_check_magic_method_public ("__isset" , ce , fptr , error_type );
2091
2105
} else if (zend_string_equals_literal (lcname , ZEND_CALL_FUNC_NAME )) {
2092
2106
zend_check_magic_method_args (2 , "__call" , ce , fptr , error_type );
2093
2107
zend_check_magic_method_non_static ("__call" , ce , fptr , error_type );
2108
+ zend_check_magic_method_public ("__call" , ce , fptr , error_type );
2094
2109
} else if (zend_string_equals_literal (lcname , ZEND_CALLSTATIC_FUNC_NAME )) {
2095
2110
zend_check_magic_method_args (2 , "__callStatic" , ce , fptr , error_type );
2096
2111
zend_check_magic_method_static ("__callStatic" , ce , fptr , error_type );
2112
+ zend_check_magic_method_public ("__callStatic" , ce , fptr , error_type );
2097
2113
} else if (zend_string_equals_literal (lcname , ZEND_TOSTRING_FUNC_NAME )) {
2098
2114
zend_check_magic_method_args (0 , "__toString" , ce , fptr , error_type );
2099
2115
zend_check_magic_method_non_static ("__toString" , ce , fptr , error_type );
2116
+ zend_check_magic_method_public ("__toString" , ce , fptr , error_type );
2100
2117
} else if (zend_string_equals_literal (lcname , ZEND_DEBUGINFO_FUNC_NAME )) {
2101
2118
zend_check_magic_method_args (0 , "__debugInfo" , ce , fptr , error_type );
2102
2119
zend_check_magic_method_non_static ("__debugInfo" , ce , fptr , error_type );
2120
+ zend_check_magic_method_public ("__debugInfo" , ce , fptr , error_type );
2103
2121
} else if (zend_string_equals_literal (lcname , "__serialize" )) {
2104
2122
zend_check_magic_method_args (0 , "__serialize" , ce , fptr , error_type );
2105
2123
zend_check_magic_method_non_static ("__serialize" , ce , fptr , error_type );
2124
+ zend_check_magic_method_public ("__serialize" , ce , fptr , error_type );
2106
2125
} else if (zend_string_equals_literal (lcname , "__unserialize" )) {
2107
2126
zend_check_magic_method_args (1 , "__unserialize" , ce , fptr , error_type );
2108
2127
zend_check_magic_method_non_static ("__unserialize" , ce , fptr , error_type );
2128
+ zend_check_magic_method_public ("__unserialize" , ce , fptr , error_type );
2109
2129
} else if (zend_string_equals_literal (lcname , "__set_state" )) {
2110
2130
zend_check_magic_method_args (1 , "__set_state" , ce , fptr , error_type );
2111
2131
zend_check_magic_method_static ("__set_state" , ce , fptr , error_type );
2132
+ zend_check_magic_method_public ("__set_state" , ce , fptr , error_type );
2112
2133
} else if (zend_string_equals_literal (lcname , "__invoke" )) {
2113
2134
zend_check_magic_method_non_static ("__invoke" , ce , fptr , error_type );
2135
+ zend_check_magic_method_public ("__invoke" , ce , fptr , error_type );
2114
2136
}
2115
2137
}
2116
2138
/* }}} */
@@ -2294,11 +2316,9 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
2294
2316
reg_function = NULL ;
2295
2317
} else if (zend_string_equals_literal (lowercase_name , ZEND_CONSTRUCTOR_FUNC_NAME )) {
2296
2318
ctor = reg_function ;
2319
+ ctor -> common .fn_flags |= ZEND_ACC_CTOR ;
2297
2320
} else if (zend_string_equals_literal (lowercase_name , ZEND_DESTRUCTOR_FUNC_NAME )) {
2298
2321
dtor = reg_function ;
2299
- if (internal_function -> num_args ) {
2300
- zend_error (error_type , "Destructor %s::%s() cannot take arguments" , ZSTR_VAL (scope -> name ), ptr -> fname );
2301
- }
2302
2322
} else if (zend_string_equals_literal (lowercase_name , ZEND_CLONE_FUNC_NAME )) {
2303
2323
clone = reg_function ;
2304
2324
} else if (zend_string_equals_literal (lowercase_name , ZEND_CALL_FUNC_NAME )) {
@@ -2368,9 +2388,6 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
2368
2388
scope -> __debugInfo = __debugInfo ;
2369
2389
scope -> __serialize = __serialize ;
2370
2390
scope -> __unserialize = __unserialize ;
2371
- if (ctor ) {
2372
- ctor -> common .fn_flags |= ZEND_ACC_CTOR ;
2373
- }
2374
2391
efree ((char * )lc_class_name );
2375
2392
}
2376
2393
return SUCCESS ;
0 commit comments