Skip to content

Commit

Permalink
- Fix problem with constructor not being inherited and called correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andi Gutmans committed Jun 23, 2002
1 parent fd904b8 commit 9c148f0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 12 additions & 3 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,9 @@ binary_assign_op_addr: {

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;
}
Expand Down

0 comments on commit 9c148f0

Please sign in to comment.