]> granicus.if.org Git - php/commitdiff
- Fix problem with constructor not being inherited and called correctly.
authorAndi Gutmans <andi@php.net>
Sun, 23 Jun 2002 15:46:58 +0000 (15:46 +0000)
committerAndi Gutmans <andi@php.net>
Sun, 23 Jun 2002 15:46:58 +0000 (15:46 +0000)
Zend/zend_compile.c
Zend/zend_execute.c

index 325025d95c5fb421047e2a454cad3317f2f8f6b5..cebaecf4e717195368bdb091fee5d313d0e6712b 100644 (file)
@@ -1476,16 +1476,25 @@ ZEND_API void function_add_ref(zend_function *function)
 
 static void do_inherit_parent_constructor(zend_class_entry *ce)
 {
-       if (ce->parent
-               && !zend_hash_exists(&ce->function_table, ce->name, ce->name_length+1)) {
-               zend_function *function;
+       zend_function *function;
 
+       if (!ce->parent || ce->constructor) {
+               return;
+       }
+
+       if (!zend_hash_exists(&ce->function_table, ce->name, ce->name_length+1)) {
                if (zend_hash_find(&ce->parent->function_table, ce->parent->name, ce->parent->name_length+1, (void **) &function)==SUCCESS) {
                        /* inherit parent's constructor */
                        zend_hash_update(&ce->function_table, ce->name, ce->name_length+1, function, sizeof(zend_function), NULL);
                        function_add_ref(function);
                }
        }
+       if (zend_hash_find(&ce->parent->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME), (void **) &function)==SUCCESS) {
+               /* inherit parent's constructor */
+               zend_hash_update(&ce->function_table, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME), function, sizeof(zend_function), NULL);
+               function_add_ref(function);
+       }
+       ce->constructor = ce->parent->constructor;
 }
 
 void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent_ce)
index 70cff0085b31a0ccd9581081d62675db83f0c851..1f65c9ce0c57d7f86e7a56e6e25691a42177eb0a 100644 (file)
@@ -1892,7 +1892,9 @@ binary_assign_op_addr_obj:
 
                                        EX(fbc) = EX(fbc_constructor);
                                        if(EX(fbc)->type == ZEND_USER_FUNCTION) { /* HACK!! */
-                                               EX(calling_scope) = Z_OBJCE_P(EX(object));
+                                               /*  The scope should be the scope of the class where the constructor
+                                                       was initially declared in */
+                                               EX(calling_scope) = EX(fbc)->common.scope;
                                        } else {
                                                EX(calling_scope) = NULL;
                                        }