]> granicus.if.org Git - php/commitdiff
- s/inheritence/inheritance/g
authorAndrei Zmievski <andrei@php.net>
Wed, 15 Dec 1999 21:26:43 +0000 (21:26 +0000)
committerAndrei Zmievski <andrei@php.net>
Wed, 15 Dec 1999 21:26:43 +0000 (21:26 +0000)
- Added is_subclass_of() function

Zend/zend_builtin_functions.c
Zend/zend_compile.c

index a870e7bf7887f7aa1bd1b3c20a78058330e86f4a..f7c9b4f9ee7d826a1c72485ffc6654651496b72c 100644 (file)
@@ -44,6 +44,7 @@ static ZEND_FUNCTION(function_exists);
 static ZEND_FUNCTION(leak);
 static ZEND_FUNCTION(get_used_files);
 static ZEND_FUNCTION(get_imported_files);
+static ZEND_FUNCTION(is_subclass_of);
 
 extern unsigned char first_arg_force_ref[];
 
@@ -67,6 +68,7 @@ static zend_function_entry builtin_functions[] = {
        ZEND_FE(leak,                           NULL)
        ZEND_FE(get_used_files,         NULL)
        ZEND_FE(get_imported_files,     NULL)
+       ZEND_FE(is_subclass_of,         NULL)
        { NULL, NULL, NULL }
 };
 
@@ -393,6 +395,45 @@ ZEND_FUNCTION(get_parent_class)
 }
 /* }}} */
 
+/* {{{ proto bool is_subclass_of(object object, string class_name)
+   Returns true if the object is part of hierarchy derived from passed class */
+ZEND_FUNCTION(is_subclass_of)
+{
+       zval **obj, **class_name;
+       char *lcname;
+       zend_class_entry *parent_ce = NULL;
+       CLS_FETCH();
+
+       if (ARG_COUNT(ht) != 2 || getParametersEx(2, &obj, &class_name)==FAILURE) {
+               RETURN_FALSE;
+       }
+
+       if ((*obj)->type != IS_OBJECT) {
+               RETURN_FALSE;
+       }
+
+       parent_ce = (*obj)->value.obj.ce->parent;
+       if (!parent_ce) {
+               RETURN_FALSE;
+       }
+
+       convert_to_string_ex(class_name);
+       lcname = estrndup((*class_name)->value.str.val, (*class_name)->value.str.len);
+       zend_str_tolower(lcname, (*class_name)->value.str.len);
+
+       do {
+               if (!strcmp(parent_ce->name, lcname)) {
+                       efree(lcname);
+                       RETURN_TRUE;
+               }
+       } while (parent_ce->parent
+             && zend_hash_find(CG(class_table), parent_ce->parent->name,
+                               parent_ce->parent->name_length+1, (void**)&parent_ce)==SUCCESS);
+       efree(lcname);
+       RETURN_FALSE;
+}
+/* }}} */
+
 /* {{{ proto bool method_exists(object object, string method)
      Checks if the class method exists ...
 */
index 879e67640624ed4a058fd792708dc4b1b058836f..e3d706ef5d854a4e14321e596501332b0f32ef51 100644 (file)
@@ -1083,7 +1083,7 @@ ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_tabl
                                        return FAILURE;
                                }
 
-                               /* Perform inheritence */
+                               /* 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;
@@ -1407,7 +1407,7 @@ void do_default_before_statement(znode *case_list, znode *default_token CLS_DC)
 void do_begin_class_declaration(znode *class_name, znode *parent_class_name CLS_DC)
 {
        zend_op *opline = get_next_op(CG(active_op_array) CLS_CC);
-       int runtime_inheritence = 0;
+       int runtime_inheritance = 0;
 
        if (CG(active_class_entry)) {
                zend_error(E_COMPILE_ERROR, "Class declarations may not be nested");
@@ -1444,7 +1444,7 @@ void do_begin_class_declaration(znode *class_name, znode *parent_class_name CLS_
 
                        zval_dtor(&parent_class_name->u.constant);
                } else {
-                       runtime_inheritence = 1;
+                       runtime_inheritance = 1;
                        CG(class_entry).parent = NULL;
                }
        } else {
@@ -1461,7 +1461,7 @@ void do_begin_class_declaration(znode *class_name, znode *parent_class_name CLS_
        opline->op2.op_type = IS_CONST;
        opline->op2.u.constant.type = IS_STRING;
        opline->op2.u.constant.refcount = 1;
-       if (runtime_inheritence) {
+       if (runtime_inheritance) {
                char *full_class_name;
 
                opline->op2.u.constant.value.str.len = parent_class_name->u.constant.value.str.len+1+CG(class_entry).name_length;