有时候在写模块的时候,需要知道可以用哪些属性,怎么样打印出目前该对象拥有的属性?
ReflectionClass
类,打印出类的结构。 class Test
{
private $property;
public $property2;
protected $property3;
function operation1()
{
//to do something...
}
function operation2($param)
{
//to do something else...
}
}
$a = new Reflectionclass("Test");
echo "<pre>";
echo $a;
echo "</pre>";
?>
@@ /var/www/html/test.php 2-16
- Constants [0] {
}
- Static properties [0] {
}
- Static methods [0] {
}
- Properties [3] {
Property [ private $property ]
Property [ public $property2 ]
Property [ protected $property3 ]
}
- Methods [2] {
Method [ public method operation1 ] {
@@ /var/www/html/test.php 8 -11
}
Method [ public method operation2 ] {
@@ /var/www/html/test.php 12 - 15
- Parameters [1] {
Parameter #0 [ $param ]
}
}
}
}
1 回答4k 阅读✓ 已解决
3 回答1.8k 阅读✓ 已解决
2 回答2.2k 阅读✓ 已解决
1 回答1.4k 阅读✓ 已解决
2 回答2.2k 阅读
1 回答569 阅读✓ 已解决
784 阅读
这个?
http://php.net/manual/zh/function.get-object-vars.php
http://php.net/manual/zh/function.get-class-methods.php
http://php.net/manual/zh/function.get-class-vars.php