From 81b536f4a63bac7e823f8e82421b18a67db6c78b Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 3 May 2005 08:52:04 +0000 Subject: [PATCH] Fixed bug #32296 (get_class_methods output has changed between 5.0.2 and 5.0.3) Now get_class_methods() shows accessible private and protected methods if it is called from class scope. --- Zend/tests/bug32296.phpt | 60 +++++++++++++++++++++++++++++++++++ Zend/zend_builtin_functions.c | 9 +++--- 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100755 Zend/tests/bug32296.phpt diff --git a/Zend/tests/bug32296.phpt b/Zend/tests/bug32296.phpt new file mode 100755 index 0000000000..81fe25df8b --- /dev/null +++ b/Zend/tests/bug32296.phpt @@ -0,0 +1,60 @@ +--TEST-- +Bug #32296 get_class_methods output has changed between 5.0.2 and 5.0.3 +--FILE-- +buggy(); +print_r(get_class_methods("square")); +print_r(get_class_methods($a)); +?> +--EXPECT-- +square +a:Array +( + [0] => x2 + [1] => buggy + [2] => unfold + [3] => __construct +) +b:Array +( + [0] => x2 + [1] => buggy + [2] => unfold + [3] => __construct +) +Array +( + [0] => buggy + [1] => __construct +) +Array +( + [0] => buggy + [1] => __construct +) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index abd5996623..34fe3db7c0 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -812,7 +812,6 @@ 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(); @@ -834,14 +833,16 @@ 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) { if ((mptr->common.fn_flags & ZEND_ACC_PUBLIC) - || (instanceof && ((mptr->common.fn_flags & ZEND_ACC_PROTECTED) || EG(scope) == mptr->common.scope))) { + || (EG(scope) && + (((mptr->common.fn_flags & ZEND_ACC_PROTECTED) && + instanceof_function(EG(scope), mptr->common.scope TSRMLS_CC)) + || ((mptr->common.fn_flags & ZEND_ACC_PRIVATE) && + 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); -- 2.40.0