100分求一个比较少见的问题 现在有一个PHP类,如何在不知其内部构造的情况下,遍历打印出其内部的所有函数名? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 呵呵这还少见啊..试试get_class_methods ()这个只能打印出类的成员函数, 而不是函数 实例化一个对象然后var_dump比如 var $c = new Class;var_dump($c); $c = new Class;var_dump($c) get_class_methods -- 返回由类的方法名组成的数组可通过 php 反射机制探知方法的相关信息 className 已知类名$reflection = new ReflectionClass('className');$aMethods = $reflection->getMethods();var_dump($aMethods); get_class_methods //返回由类的方法名组成的数组get_class_vars //返回由类的默认属性组成的数组 php5的话就用反射机制咯。。ReflectionIntroductionPHP 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<?phpReflection::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 ] { } }} 函数名是不是都有FUNCTION?你就指定程序把FUNCTION后面那个单词+括号提出来就是了 下面为我的一个类: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()这个不能得到私有的方法 php中ifelse问题 求高手 拯救我PHP变量后面带[]是什么 意思 我们这里需要招一个php的程序员,不知道在这里提示不是不妥当 php 连接远程mysql数据库 出现错误: Lost connection to MySQL server during query PHP怪事:总出错,但找不到原因 是太难了还是太简单了,帮我看看吧 再给分:怎样判断checkbox被选中了? 请问我的修改程序错在哪里?啊能否给个完整的例子谢谢! 如何实现GB或big5与UTF8实现转化? 请问如何向access中创建表? 急,关于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()这个不能得到私有的方法