From: Andrei Zmievski Date: Sat, 26 Feb 2000 17:54:00 +0000 (+0000) Subject: Added get_class_vars() and get_object_vars() functions. X-Git-Tag: PHP-4.0-RC1~388 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=685fd42965088479af4b120fa6c7a7a47a957b7e;p=php Added get_class_vars() and get_object_vars() functions. --- diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 24ea5c2948..a36da254d1 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -51,6 +51,8 @@ static ZEND_FUNCTION(crash); static ZEND_FUNCTION(get_used_files); static ZEND_FUNCTION(get_imported_files); static ZEND_FUNCTION(is_subclass_of); +static ZEND_FUNCTION(get_class_vars); +static ZEND_FUNCTION(get_object_vars); extern unsigned char first_arg_force_ref[]; @@ -79,6 +81,8 @@ static zend_function_entry builtin_functions[] = { ZEND_FE(get_used_files, NULL) ZEND_FE(get_imported_files, NULL) ZEND_FE(is_subclass_of, NULL) + ZEND_FE(get_class_vars, NULL) + ZEND_FE(get_object_vars, NULL) { NULL, NULL, NULL } }; @@ -448,6 +452,55 @@ ZEND_FUNCTION(is_subclass_of) } /* }}} */ +/* {{{ proto array get_class_vars(string class_name) + Returns an array of default properties of the class */ +ZEND_FUNCTION(get_class_vars) +{ + zval **class_name; + char *lcname; + zend_class_entry *ce; + zval *tmp; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) { + 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); + + if (zend_hash_find(CG(class_table), lcname, (*class_name)->value.str.len+1, (void **)&ce)==FAILURE) { + efree(lcname); + RETURN_FALSE; + } else { + efree(lcname); + array_init(return_value); + zend_hash_copy(return_value->value.ht, &ce->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + } +} +/* }}} */ + +/* {{{ proto array get_object_vars(object obj) + Returns an array of object properties */ +ZEND_FUNCTION(get_object_vars) +{ + zval **obj; + zval *tmp; + + if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &obj) == FAILURE) { + RETURN_FALSE; + } + + if ((*obj)->type != IS_OBJECT) { + RETURN_FALSE; + } + + array_init(return_value); + zend_hash_copy(return_value->value.ht, (*obj)->value.obj.properties, + (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); +} +/* }}} */ + /* {{{ proto bool method_exists(object object, string method) Checks if the class method exists ... */