PHP 反射 ReflectionClass
网上例子
<?php
class ClassA{
public function funcAa(){
}
public function funcAb(){
}
public function funcAc(){
}
}
?>
classB.php
<?php
include './classA.php';
class ClassB extends ClassA{
public function funcBa(){
}
public function funcBb(){
}
public function funcBc(){
}
public function funcAa(){
parent::funcAa();
}
}
当我需要找出ClassB里面的所有方法的时候结果如下:
$reflection= new ReflectionClass('ClassB');
$reflection= new ReflectionClass('ClassB');
$array = ''";
foreach($reflection->getMethods() as $obj){
if($obj->class == $reflection->getName()){
//$reflection->getName() 获取类名
$array[] = $obj->name;
}
}
echo '<pre>';
print_r($array);
print_r($reflection->getMethods());
结果:
Array
(
[0] => ReflectionMethod Object
(
[name] => funcBa
[class] => ClassB
)
[1] => ReflectionMethod Object
(
[name] => funcBb
[class] => ClassB
)
[2] => ReflectionMethod Object
(
[name] => funcBc
[class] => ClassB
)
[3] => ReflectionMethod Object
(
[name] => funcAa
[class] => ClassB
)......
相关内容请看php文档
http://www.php.net/manual/zh/class.reflectionclass.php