From: Marcus Boerger Date: Tue, 12 Oct 2004 11:03:35 +0000 (+0000) Subject: MFH Fix visibility of get_class_vars() and get_class_methods() X-Git-Tag: php-5.0.3RC1~148 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8360ce27aabaddb9aed411dbf2feac579c488233;p=php MFH Fix visibility of get_class_vars() and get_class_methods() --- diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 545998cf8c..6d545aa228 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -663,6 +663,7 @@ ZEND_FUNCTION(get_class_vars) { zval **class_name; zend_class_entry *ce, **pce; + int instanceof; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) { ZEND_WRONG_PARAM_COUNT(); @@ -674,6 +675,9 @@ ZEND_FUNCTION(get_class_vars) RETURN_FALSE; } else { ce = *pce; + + instanceof = EG(scope) && instanceof_function(EG(scope), ce TSRMLS_CC); + array_init(return_value); if (zend_hash_num_elements(&ce->default_properties) > 0) { @@ -690,9 +694,14 @@ ZEND_FUNCTION(get_class_vars) zend_hash_get_current_key_ex(&ce->default_properties, &key, &key_len, &num_index, 0, &pos); zend_hash_move_forward_ex(&ce->default_properties, &pos); zend_unmangle_property_name(key, &class_name, &prop_name); - if (class_name && class_name[0] != '*' && strcmp(class_name, ce->name)) { - /* filter privates from base classes */ - continue; + if (class_name) { + if (class_name[0] != '*' && strcmp(class_name, ce->name)) { + /* filter privates from base classes */ + continue; + } else if (!instanceof) { + /* filter protected if not inside class */ + continue; + } } /* copy: enforce read only access */ @@ -776,6 +785,7 @@ ZEND_FUNCTION(get_class_methods) zend_class_entry *ce = NULL, **pce; HashPosition pos; zend_function *mptr; + int instanceof; if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class)==FAILURE) { ZEND_WRONG_PARAM_COUNT(); @@ -797,18 +807,22 @@ ZEND_FUNCTION(get_class_methods) RETURN_NULL(); } + instanceof = EG(scope) && instanceof_function(EG(scope), ce TSRMLS_CC); + array_init(return_value); zend_hash_internal_pointer_reset_ex(&ce->function_table, &pos); while (zend_hash_get_current_data_ex(&ce->function_table, (void **) &mptr, &pos) == SUCCESS) { - MAKE_STD_ZVAL(method_name); - ZVAL_STRING(method_name, mptr->common.function_name, 1); - zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL); + if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC) + || (instanceof && ((mptr->common.fn_flags & ZEND_ACC_PROTECTED) || EG(scope) == mptr->common.scope))) { + MAKE_STD_ZVAL(method_name); + ZVAL_STRING(method_name, mptr->common.function_name, 1); + zend_hash_next_index_insert(return_value->value.ht, &method_name, sizeof(zval *), NULL); + } zend_hash_move_forward_ex(&ce->function_table, &pos); } } /* }}} */ -\ /* {{{ proto bool method_exists(object object, string method)