现在有一个PHP类,如何在不知其内部构造的情况下,遍历打印出其内部的所有函数名?

解决方案 »

  1.   

    呵呵
    这还少见啊..试试get_class_methods ()这个只能打印出类的成员函数, 而不是函数
      

  2.   

    实例化一个对象然后var_dump比如 
    var $c = new Class;
    var_dump($c);
      

  3.   

    $c = new Class;
    var_dump($c)
      

  4.   

    get_class_methods -- 返回由类的方法名组成的数组
    可通过 php 反射机制探知方法的相关信息
      

  5.   

    className 已知类名
    $reflection = new ReflectionClass('className');
    $aMethods = $reflection->getMethods();
    var_dump($aMethods);
      

  6.   

    get_class_methods //返回由类的方法名组成的数组get_class_vars //返回由类的默认属性组成的数组 
      

  7.   

    php5的话就用反射机制咯。。Reflection
    Introduction
    PHP 5 comes with a complete reflection API that adds the ability to reverse-engineer classes, interfaces, functions and methods as well as extensions. Additionally, the reflection API also offers ways of retrieving doc comments for functions, classes and methods. 例子 19-31. Basic usage of the reflection API<?php
    Reflection::export(new ReflectionClass('Exception'));
    ?>  上例将输出:Class [ <internal> class Exception ] {  - Constants [0] {
      }  - Static properties [0] {
      }  - Static methods [0] {
      }  - Properties [6] {
        Property [ <default> protected $message ]
        Property [ <default> private $string ]
        Property [ <default> protected $code ]
        Property [ <default> protected $file ]
        Property [ <default> protected $line ]
        Property [ <default> private $trace ]
      }  - Methods [9] {
        Method [ <internal> final private method __clone ] {
        }    Method [ <internal> <ctor> public method __construct ] {      - Parameters [2] {
            Parameter #0 [ <required> $message ]
            Parameter #1 [ <required> $code ]
          }
        }    Method [ <internal> final public method getMessage ] {
        }    Method [ <internal> final public method getCode ] {
        }    Method [ <internal> final public method getFile ] {
        }    Method [ <internal> final public method getLine ] {
        }    Method [ <internal> final public method getTrace ] {
        }    Method [ <internal> final public method getTraceAsString ] {
        }    Method [ <internal> public method __toString ] {
        }
      }
    }
     
      

  8.   

    函数名是不是都有FUNCTION?你就指定程序把FUNCTION后面那个单词+括号提出来就是了
      

  9.   

    下面为我的一个类:
    class ParserXml
    {
        private $config=array();
        
        public function ParserXml()
        {}
        
        public function parserXml2($filename)
        {}
        
        
        private function XmlToArray($config,$DomDocument)
        {}
        
        public function aaa($filename){
        }
        
        private function object2Array($object)
        {}
    }下面为我的test类:include 'parse.php';$p=new ParserXml();
    print_r(get_class_methods(get_class($p)));echo "<br/><br/>";$reflection = new ReflectionClass(get_class($p));print_r($reflection->getMethods());
    输出的结果如下:
    Array
    (
        [0] => ParserXml
        [1] => parserXml2
        [2] => aaa
    )
    <br/><br/>Array
    (
        [0] => ReflectionMethod Object
            (
                [name] => ParserXml
                [class] => ParserXml
            )
     
        [1] => ReflectionMethod Object
            (
                [name] => parserXml2
                [class] => ParserXml
            )
     
        [2] => ReflectionMethod Object
            (
                [name] => XmlToArray
                [class] => ParserXml
            )
     
        [3] => ReflectionMethod Object
            (
                [name] => aaa
                [class] => ParserXml
            )
     
        [4] => ReflectionMethod Object
            (
                [name] => object2Array
                [class] => ParserXml
            )
     
    )get_class_methods()这个不能得到私有的方法