]> granicus.if.org Git - php/commitdiff
Automatically register constructor, destructor, and clone function when
authorAndrei Zmievski <andrei@php.net>
Fri, 10 Jan 2003 14:41:53 +0000 (14:41 +0000)
committerAndrei Zmievski <andrei@php.net>
Fri, 10 Jan 2003 14:41:53 +0000 (14:41 +0000)
class methods are registered.

Zend/zend_API.c

index 13207c177db5325cba08773ffefc9e592850ccaa..b3c08b14c78ed277152fa31a0147c50bbb3b3205 100644 (file)
@@ -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**)&reg_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;
 }