]> granicus.if.org Git - php/commitdiff
Fixed bug #32296 (get_class_methods output has changed between 5.0.2 and 5.0.3)
authorDmitry Stogov <dmitry@php.net>
Tue, 3 May 2005 08:50:13 +0000 (08:50 +0000)
committerDmitry Stogov <dmitry@php.net>
Tue, 3 May 2005 08:50:13 +0000 (08:50 +0000)
Now get_class_methods() shows accessible private and protected methods if it is called from class scope.

NEWS
Zend/tests/bug32296.phpt [new file with mode: 0755]
Zend/zend_builtin_functions.c

diff --git a/NEWS b/NEWS
index f2caba69a5630f85e965a0c9aa6063ee8fa9257d..2dd8ddc407292835ea4e798c44ec2f66fdcc7a5a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,8 @@ PHP                                                                        NEWS
   (Uwe Schindler)
 - Fixed bug #32405 (mysqli::fetch() returns bad data - 64bit problem). (Andrey)
 - Fixed bug #32282 (Segfault in mysqli_fetch_array on 64-bit). (Georg)
+- Fixed bug #32296 (get_class_methods output has changed between 5.0.2 and
+  5.0.3). (Dmitry)
 - Fixed bug #32245 (xml_parser_free() in a function assigned to the xml parser
   gives a segfault). (Rob)
 - Fixed bug #32080 (segfault when assigning object to itself with
diff --git a/Zend/tests/bug32296.phpt b/Zend/tests/bug32296.phpt
new file mode 100755 (executable)
index 0000000..81fe25d
--- /dev/null
@@ -0,0 +1,60 @@
+--TEST--
+Bug #32296 get_class_methods output has changed between 5.0.2 and 5.0.3 
+--FILE--
+<?php
+abstract class space{
+       function __construct(){}
+       abstract protected function unfold();
+}
+
+abstract class shape extends space{
+       private function x1() {}
+       protected final function unfold(){}
+}
+
+abstract class quad extends shape{
+       private function x2() {}
+       function buggy(){
+               $c = get_class($this);
+               $a = get_class_methods(get_class($this));
+               $b = get_class_methods($this);
+               print($c."\n".'a:');
+               print_r($a);
+               print('b:');
+               print_r($b);
+       }
+}
+
+class square extends quad{}
+
+$a = new square();
+$a->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
+)
index 1988e3a992f070f454fbde06c78d2964904401e0..8034fbe6934c13aa8dff624ee74ab22d56b4ff19 100644 (file)
@@ -802,7 +802,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();
@@ -824,14 +823,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);