mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Add common code for magic method assignment
This was repeated three times.
This commit is contained in:
parent
05e9197c51
commit
7fd4212cc0
4 changed files with 45 additions and 113 deletions
|
@ -2138,6 +2138,44 @@ ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce,
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
ZEND_API void zend_add_magic_method(zend_class_entry *ce, zend_function *fptr, zend_string *lcname)
|
||||||
|
{
|
||||||
|
if (ZSTR_VAL(lcname)[0] != '_' || ZSTR_VAL(lcname)[1] != '_') {
|
||||||
|
/* pass */
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
|
||||||
|
ce->clone = fptr;
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
|
||||||
|
ce->constructor = fptr;
|
||||||
|
ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME)) {
|
||||||
|
ce->destructor = fptr;
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
|
||||||
|
ce->__get = fptr;
|
||||||
|
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
|
||||||
|
ce->__set = fptr;
|
||||||
|
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
|
||||||
|
ce->__call = fptr;
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
|
||||||
|
ce->__unset = fptr;
|
||||||
|
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
|
||||||
|
ce->__isset = fptr;
|
||||||
|
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
|
||||||
|
ce->__callstatic = fptr;
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
|
||||||
|
ce->__tostring = fptr;
|
||||||
|
} else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
|
||||||
|
ce->__debugInfo = fptr;
|
||||||
|
} else if (zend_string_equals_literal(lcname, "__serialize")) {
|
||||||
|
ce->__serialize = fptr;
|
||||||
|
} else if (zend_string_equals_literal(lcname, "__unserialize")) {
|
||||||
|
ce->__unserialize = fptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* registers all functions in *library_functions in the function hash */
|
/* registers all functions in *library_functions in the function hash */
|
||||||
ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type) /* {{{ */
|
ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_function_entry *functions, HashTable *function_table, int type) /* {{{ */
|
||||||
{
|
{
|
||||||
|
@ -2294,47 +2332,9 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scope) {
|
if (scope) {
|
||||||
/* Look for ctor, dtor, clone */
|
zend_check_magic_method_implementation(
|
||||||
if (ZSTR_VAL(lowercase_name)[0] != '_' || ZSTR_VAL(lowercase_name)[1] != '_') {
|
scope, reg_function, lowercase_name, E_CORE_ERROR);
|
||||||
reg_function = NULL;
|
zend_add_magic_method(scope, reg_function, lowercase_name);
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_CONSTRUCTOR_FUNC_NAME)) {
|
|
||||||
scope->constructor = reg_function;
|
|
||||||
scope->constructor->common.fn_flags |= ZEND_ACC_CTOR;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_DESTRUCTOR_FUNC_NAME)) {
|
|
||||||
scope->destructor = reg_function;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_CLONE_FUNC_NAME)) {
|
|
||||||
scope->clone = reg_function;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_CALL_FUNC_NAME)) {
|
|
||||||
scope->__call = reg_function;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_CALLSTATIC_FUNC_NAME)) {
|
|
||||||
scope->__callstatic = reg_function;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_TOSTRING_FUNC_NAME)) {
|
|
||||||
scope->__tostring = reg_function;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_GET_FUNC_NAME)) {
|
|
||||||
scope->__get = reg_function;
|
|
||||||
scope->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_SET_FUNC_NAME)) {
|
|
||||||
scope->__set = reg_function;
|
|
||||||
scope->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_UNSET_FUNC_NAME)) {
|
|
||||||
scope->__unset = reg_function;
|
|
||||||
scope->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_ISSET_FUNC_NAME)) {
|
|
||||||
scope->__isset = reg_function;
|
|
||||||
scope->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, ZEND_DEBUGINFO_FUNC_NAME)) {
|
|
||||||
scope->__debugInfo = reg_function;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, "__serialize")) {
|
|
||||||
scope->__serialize = reg_function;
|
|
||||||
} else if (zend_string_equals_literal(lowercase_name, "__unserialize")) {
|
|
||||||
scope->__unserialize = reg_function;
|
|
||||||
} else {
|
|
||||||
reg_function = NULL;
|
|
||||||
}
|
|
||||||
if (reg_function) {
|
|
||||||
zend_check_magic_method_implementation(
|
|
||||||
scope, reg_function, lowercase_name, E_CORE_ERROR);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ptr++;
|
ptr++;
|
||||||
count++;
|
count++;
|
||||||
|
|
|
@ -320,6 +320,7 @@ ZEND_API void zend_collect_module_handlers(void);
|
||||||
ZEND_API void zend_destroy_modules(void);
|
ZEND_API void zend_destroy_modules(void);
|
||||||
ZEND_API void zend_check_magic_method_implementation(
|
ZEND_API void zend_check_magic_method_implementation(
|
||||||
const zend_class_entry *ce, const zend_function *fptr, zend_string *lcname, int error_type);
|
const zend_class_entry *ce, const zend_function *fptr, zend_string *lcname, int error_type);
|
||||||
|
ZEND_API void zend_add_magic_method(zend_class_entry *ce, zend_function *fptr, zend_string *lcname);
|
||||||
|
|
||||||
ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
|
ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry);
|
||||||
ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);
|
ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce);
|
||||||
|
|
|
@ -6509,40 +6509,9 @@ zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string *name,
|
||||||
ZSTR_VAL(ce->name), ZSTR_VAL(name));
|
ZSTR_VAL(ce->name), ZSTR_VAL(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZSTR_VAL(lcname)[0] != '_' || ZSTR_VAL(lcname)[1] != '_') {
|
zend_add_magic_method(ce, (zend_function *) op_array, lcname);
|
||||||
/* pass */
|
if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
|
|
||||||
ce->constructor = (zend_function *) op_array;
|
|
||||||
ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
|
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME)) {
|
|
||||||
ce->destructor = (zend_function *) op_array;
|
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
|
|
||||||
ce->clone = (zend_function *) op_array;
|
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
|
|
||||||
ce->__call = (zend_function *) op_array;
|
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
|
|
||||||
ce->__callstatic = (zend_function *) op_array;
|
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
|
|
||||||
ce->__get = (zend_function *) op_array;
|
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
|
|
||||||
ce->__set = (zend_function *) op_array;
|
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
|
|
||||||
ce->__unset = (zend_function *) op_array;
|
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
|
|
||||||
ce->__isset = (zend_function *) op_array;
|
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
|
|
||||||
ce->__tostring = (zend_function *) op_array;
|
|
||||||
add_stringable_interface(ce);
|
add_stringable_interface(ce);
|
||||||
} else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
|
|
||||||
ce->__debugInfo = (zend_function *) op_array;
|
|
||||||
} else if (zend_string_equals_literal(lcname, "__serialize")) {
|
|
||||||
ce->__serialize = (zend_function *) op_array;
|
|
||||||
} else if (zend_string_equals_literal(lcname, "__unserialize")) {
|
|
||||||
ce->__unserialize = (zend_function *) op_array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return lcname;
|
return lcname;
|
||||||
|
|
|
@ -1559,44 +1559,6 @@ static void zend_do_implement_interfaces(zend_class_entry *ce, zend_class_entry
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
static void zend_add_magic_methods(zend_class_entry* ce, zend_string* mname, zend_function* fe) /* {{{ */
|
|
||||||
{
|
|
||||||
if (ZSTR_VAL(mname)[0] != '_' || ZSTR_VAL(mname)[1] != '_') {
|
|
||||||
/* pass */
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_CLONE_FUNC_NAME)) {
|
|
||||||
ce->clone = fe;
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
|
|
||||||
ce->constructor = fe;
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_DESTRUCTOR_FUNC_NAME)) {
|
|
||||||
ce->destructor = fe;
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_GET_FUNC_NAME)) {
|
|
||||||
ce->__get = fe;
|
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_SET_FUNC_NAME)) {
|
|
||||||
ce->__set = fe;
|
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_CALL_FUNC_NAME)) {
|
|
||||||
ce->__call = fe;
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_UNSET_FUNC_NAME)) {
|
|
||||||
ce->__unset = fe;
|
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_ISSET_FUNC_NAME)) {
|
|
||||||
ce->__isset = fe;
|
|
||||||
ce->ce_flags |= ZEND_ACC_USE_GUARDS;
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_CALLSTATIC_FUNC_NAME)) {
|
|
||||||
ce->__callstatic = fe;
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_TOSTRING_FUNC_NAME)) {
|
|
||||||
ce->__tostring = fe;
|
|
||||||
} else if (zend_string_equals_literal(mname, ZEND_DEBUGINFO_FUNC_NAME)) {
|
|
||||||
ce->__debugInfo = fe;
|
|
||||||
} else if (zend_string_equals_literal(mname, "__serialize")) {
|
|
||||||
ce->__serialize = fe;
|
|
||||||
} else if (zend_string_equals_literal(mname, "__unserialize")) {
|
|
||||||
ce->__unserialize = fe;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* }}} */
|
|
||||||
|
|
||||||
static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_string *key, zend_function *fn) /* {{{ */
|
static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_string *key, zend_function *fn) /* {{{ */
|
||||||
{
|
{
|
||||||
zend_function *existing_fn = NULL;
|
zend_function *existing_fn = NULL;
|
||||||
|
@ -1659,7 +1621,7 @@ static void zend_add_trait_method(zend_class_entry *ce, zend_string *name, zend_
|
||||||
new_fn->common.function_name = name;
|
new_fn->common.function_name = name;
|
||||||
function_add_ref(new_fn);
|
function_add_ref(new_fn);
|
||||||
fn = zend_hash_update_ptr(&ce->function_table, key, new_fn);
|
fn = zend_hash_update_ptr(&ce->function_table, key, new_fn);
|
||||||
zend_add_magic_methods(ce, key, fn);
|
zend_add_magic_method(ce, fn, key);
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue