From: Andi Gutmans Date: Sun, 23 Jun 2002 15:46:58 +0000 (+0000) Subject: - Fix problem with constructor not being inherited and called correctly. X-Git-Tag: php-4.3.0dev_zend2_alpha2~136 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c148f0d842b564bd1b54a32bd582fad8ddc6be8;p=php - Fix problem with constructor not being inherited and called correctly. --- diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 325025d95c..cebaecf4e7 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -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) diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 70cff0085b..1f65c9ce0c 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -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; }