PHP 反射 ReflectionClass

PHP 反射 ReflectionClass
网上例子


classB.php

当我需要找出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 '
';
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

你可能感兴趣的:(PHP 反射 ReflectionClass)