现在有一个PHP类,如何在不知其内部构造的情况下,遍历打印出其内部的所有函数名?
解决方案 »
- plesk 8.4.0 版 文件权限修改
- mysql_num_rows(): supplied argument is not a valid MySQL result resource in E:\apache\Apache2\sites\
- 迫切需要解决的mysql字符集问题,高手们进来看看
- 1亿条数据,如何快速的从一张表导入到另一张表
- 今天看到老板解雇一个同事,心里感觉很难受
- 请问php中整除用哪个运算符呀,谢谢
- 文本留言第三问
- PDF文件的问题?
- 如何让PHP自动跳转到另一页?
- php 如何获取js的prompt里面的值
- 急,关于is_int的问题,高手进,解答。。。
- php函数名字大小写没区别吗?
这还少见啊..试试get_class_methods ()这个只能打印出类的成员函数, 而不是函数
var $c = new Class;
var_dump($c);
var_dump($c)
可通过 php 反射机制探知方法的相关信息
$reflection = new ReflectionClass('className');
$aMethods = $reflection->getMethods();
var_dump($aMethods);
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 ] {
}
}
}
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()这个不能得到私有的方法