]> granicus.if.org Git - php/commitdiff
- Andrei, this is for you!
authorAndi Gutmans <andi@php.net>
Fri, 9 Jun 2000 14:40:14 +0000 (14:40 +0000)
committerAndi Gutmans <andi@php.net>
Fri, 9 Jun 2000 14:40:14 +0000 (14:40 +0000)
- Add zend_register_internal_class_ex() which allows you to specify a
- parent to inherit from. You can either specify the parent directly or via
- its name.

Zend/zend_API.c
Zend/zend_API.h
Zend/zend_compile.c
Zend/zend_compile.h

index 8e28c9ddb150710cc054c2470f148841f21f631d..1fe7a4627900148df0d69b9282926e3321fd95fd 100644 (file)
@@ -867,6 +867,29 @@ int zend_next_free_module(void)
        return ++module_count;
 }
 
+/* If parent_ce is not NULL then it inherits from parent_ce
+ * If parent_ce is NULL and parent_name isn't then it looks for the parent and inherits from it
+ * If both parent_ce and parent_name are NULL it does a regular class registration
+ * If parent_name is specified but not found NULL is returned
+ */
+ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce, char *parent_name)
+{
+       zend_class_entry *register_class;
+       CLS_FETCH();
+
+       if (!parent_ce && parent_name) {
+                       if (zend_hash_find(CG(class_table), parent_name, strlen(parent_name)+1, (void **) &parent_ce)==FAILURE) {
+                               return NULL;
+                       }
+       }
+
+       register_class = zend_register_internal_class(class_entry);
+
+       if (parent_ce) {
+               do_inheritance(register_class, parent_ce);
+       }
+       return register_class;
+}
 
 ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry)
 {
index 2345ef023af0be5af6b086cf46a000f354a8e234..8dace5824bfe620138a702c655f85a9eb143fd41 100644 (file)
@@ -111,7 +111,10 @@ ZEND_API int ParameterPassedByReference(int ht, uint n);
 int zend_register_functions(zend_function_entry *functions, HashTable *function_table);
 void zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table);
 ZEND_API int zend_register_module(zend_module_entry *module_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, char *parent_name);
+
 ZEND_API zend_module_entry *zend_get_module(int module_number);
 ZEND_API int zend_disable_function(char *function_name, uint function_name_length);
 
index 557a0ea4bac6f0d12d8ef7ba332aa903c39dd590..3d1666e32627282aaf3c7ed284f17a70038e8783 100644 (file)
@@ -1055,6 +1055,18 @@ static void do_inherit_parent_constructor(zend_class_entry *ce)
        }
 }
 
+void do_inheritance(zend_class_entry *ce, zend_class_entry *parent_ce)
+{
+       zend_function tmp_zend_function;
+       zval *tmp;
+
+       /* Perform inheritance */
+       zend_hash_merge(&ce->default_properties, &parent_ce->default_properties, (void (*)(void *)) zval_add_ref, (void *) &tmp, sizeof(zval *), 0);
+       zend_hash_merge(&ce->function_table, &parent_ce->function_table, (void (*)(void *)) function_add_ref, &tmp_zend_function, sizeof(zend_function), 0);
+       ce->parent = parent_ce;
+       do_inherit_parent_constructor(ce);
+}
+
 
 ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_table, HashTable *class_table, int compile_time)
 {
@@ -1097,8 +1109,6 @@ ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_tabl
                case ZEND_DECLARE_INHERITED_CLASS: {
                                zend_class_entry *ce, *parent_ce;
                                char *class_name, *parent_name;
-                               zend_function tmp_zend_function;
-                               zval *tmp;
                                int found_ce;
 
                                
@@ -1129,12 +1139,7 @@ ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_tabl
                                        return FAILURE;
                                }
 
-                               /* Perform inheritance */
-                               zend_hash_merge(&ce->default_properties, &parent_ce->default_properties, (void (*)(void *)) zval_add_ref, (void *) &tmp, sizeof(zval *), 0);
-                               zend_hash_merge(&ce->function_table, &parent_ce->function_table, (void (*)(void *)) function_add_ref, &tmp_zend_function, sizeof(zend_function), 0);
-                               ce->parent = parent_ce;
-                               do_inherit_parent_constructor(ce);
-
+                               do_inheritance(ce, parent_ce);
 
                                /* Register the derived class */
                                if (zend_hash_add(class_table, class_name, strlen(class_name)+1, ce, sizeof(zend_class_entry), NULL)==FAILURE) {
index f7b51287849c39b8b0c103efee8e222c94f98108..a244811ea9981a712c2819096050859bba586f22 100644 (file)
@@ -286,6 +286,7 @@ void do_begin_class_member_function_call(znode *class_name, znode *function_name
 void do_end_function_call(znode *function_name, znode *result, znode *argument_list, int is_method, int is_dynamic_fcall CLS_DC);
 void do_return(znode *expr, int do_end_vparse CLS_DC);
 ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_table, HashTable *class_table, int compile_time);
+void do_inheritance(zend_class_entry *ce, zend_class_entry *parent_ce);
 void do_early_binding(CLS_D);
 
 void do_pass_param(znode *param, int op, int offset CLS_DC);