From efaa31e940b35b1344c8f7fca4ce1f220e2ff57b Mon Sep 17 00:00:00 2001 From: Andrei Zmievski Date: Fri, 10 Jan 2003 14:41:53 +0000 Subject: [PATCH] Automatically register constructor, destructor, and clone function when class methods are registered. --- Zend/zend_API.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 13207c177d..b3c08b14c7 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1042,11 +1042,12 @@ ZEND_API int zend_startup_module(zend_module_entry *module) int zend_register_functions(zend_class_entry *scope, zend_function_entry *functions, HashTable *function_table, int type TSRMLS_DC) { zend_function_entry *ptr = functions; - zend_function function; + zend_function function, *reg_function; zend_internal_function *internal_function = (zend_internal_function *)&function; int count=0, unload=0; HashTable *target_function_table = function_table; int error_type; + zend_function *ctor = NULL, *dtor = NULL, *clone = NULL; if (type==MODULE_PERSISTENT) { error_type = E_CORE_WARNING; @@ -1070,10 +1071,25 @@ int zend_register_functions(zend_class_entry *scope, zend_function_entry *functi zend_unregister_functions(functions, count, target_function_table TSRMLS_CC); return FAILURE; } - if (zend_hash_add(target_function_table, ptr->fname, strlen(ptr->fname)+1, &function, sizeof(zend_function), NULL) == FAILURE) { + if (zend_hash_add(target_function_table, ptr->fname, strlen(ptr->fname)+1, &function, sizeof(zend_function), (void**)®_function) == FAILURE) { unload=1; break; } + if (scope) { + /* + * If it's an old-style constructor, store it only if we don't have + * a constructor already. + */ + if (!strcmp(ptr->fname, scope->name) && !ctor) { + ctor = reg_function; + } else if (!strcmp(ptr->fname, ZEND_CONSTRUCTOR_FUNC_NAME)) { + ctor = reg_function; + } else if (!strcmp(ptr->fname, ZEND_DESTRUCTOR_FUNC_NAME)) { + dtor = reg_function; + } else if (!strcmp(ptr->fname, ZEND_CLONE_FUNC_NAME)) { + clone = reg_function; + } + } ptr++; count++; } @@ -1087,6 +1103,11 @@ int zend_register_functions(zend_class_entry *scope, zend_function_entry *functi zend_unregister_functions(functions, count, target_function_table TSRMLS_CC); return FAILURE; } + if (scope) { + scope->constructor = ctor; + scope->destructor = dtor; + scope->clone = clone; + } return SUCCESS; } -- 2.40.0