作者在 2013-01-15 08:55:07 发布以下内容
<?php
class Class1{
public $var1 = 'var1';
public $var2 = 'var2';
private $var3 = 'var3';
public function method1(){}
public function method2(){}
private function method3(){}
}
print_r(get_class_methods(Class1));
print_r(get_class_vars(Class1));
//用反射类可以获得私有属性和私有方法
$ref = new ReflectionClass(Class1);
print_r($ref->getMethods());
print_r($ref->getProperties());
输出
Array
(
[0] => method1
[1] => method2
)
Array
(
[var1] => var1
[var2] => var2
)
Array
(
[0] => ReflectionMethod Object
(
[name] => method1
[class] => Class1
)
[1] => ReflectionMethod Object
(
[name] => method2
[class] => Class1
)
[2] => ReflectionMethod Object
(
[name] => method3
[class] => Class1
)
)
Array
(
[0] => ReflectionProperty Object
(
[name] => var1
[class] => Class1
)
[1] => ReflectionProperty Object
(
[name] => var2
[class] => Class1
)
[2] => ReflectionProperty Object
(
[name] => var3
[class] => Class1
)
)