1
0
mirror of https://github.com/php/php-src.git synced 2026-04-19 22:11:12 +02:00

- Andrei, this is for you!

- 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.
This commit is contained in:
Andi Gutmans
2000-06-09 14:40:14 +00:00
parent ef1d6987fd
commit eb0e694665
4 changed files with 40 additions and 8 deletions

View 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)
{

View 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);

View 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) {

View 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);