]> granicus.if.org Git - php/commitdiff
- Fix visibility in get_class_vars() and get_class_methods()
authorMarcus Boerger <helly@php.net>
Tue, 12 Oct 2004 11:01:08 +0000 (11:01 +0000)
committerMarcus Boerger <helly@php.net>
Tue, 12 Oct 2004 11:01:08 +0000 (11:01 +0000)
# Still there is a problem/error in the executor, i'll have a look

Zend/zend_builtin_functions.c

index 93e9a9bc93c04018fc3cc496aca2d27689f102f7..b3ec841fd4a417092bef7e0fb1ea575da0a86c3b 100644 (file)
@@ -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)