您好,欢迎访问一九零五行业门户网

如何知道一个类实例有什么方法和属性

怎么知道一个类实例有什么方法和属性?
怎么知道一个类实例有什么方法和属性?
------解决方案--------------------
例子 1. get_class_methods() 示例
运行结果:
myclass
myfunc1
myfunc2
例子 1. get_class_vars() 示例
$value) {
echo $name : $value\n;
}
?>
运行结果:
// 在 php 4.2.0 之前
var2 : xyz
var3 : 100
// 从 php 4.2.0 开始
var1 :
var2 : xyz
var3 : 100
------解决方案--------------------
搜索下php手册,里面有一个反射概念(reflection)
php codeabc; } }//instantiate the object$b = new a();//instantiate the reflection object$reflector = new reflectionclass('a');//display the object properties$properties = $reflector->getproperties();foreach($properties as $property){ echo \$b->, $property->getname(), => , $b->{$property->getname()}, \n;}//display the object methods$methods = $reflector->getmethods();foreach($methods as $method){ echo \$b->, $method->getname(), => , $b->{$method->getname()}(), \n;}

其它类似信息

推荐信息