可以使用反射类机制,如下
<?php
class Test{
public $var1 = 'var1';
public $var2 = 'var2';
private $var3 = 'var3';
public function method1(){}
public function method2(){}
private function method3(){}
}
echo "<pre>";
print_r(get_class_methods(new Test));echo "<br/>";
print_r(get_class_vars(get_class(new Test)));echo "<br/>";
//用反射类可以获得私有属性和私有方法
$ref = new ReflectionClass(new Test);
print_r($ref->getMethods());echo "<br/>";
print_r($ref->getProperties());
如下显示