使用反射(Reflection)API
来源:互联网 发布:淘宝6度女装模特是谁 编辑:程序博客网 时间:2024/05/24 05:56
<?php//使用反射(Reflection)API//ReflectionClass Reflectionclass person{ const p=3.14;//类常量,常量不加$ static $b=3; protected $name='李四'; public $sex='男'; protected function say(){ } public function walk(){ } static function study(){ } } $person=new ReflectionClass('person');//实例化反射对象 Reflection::export($person);//获取类的信息/*Class [ <user> class person ] { @@ D:\wamp\www\1204\t2.php 3-15 - Constants [1] { Constant [ double p ] { 3.14 } } - Static properties [1] { Property [ public static $b ] } - Static methods [1] { Method [ <user> static public method study ] { @@ D:\wamp\www\1204\t2.php 13 - 14 } } - Properties [2] { Property [ <default> protected $name ] Property [ <default> public $sex ] } - Methods [2] { Method [ <user> protected method say ] { @@ D:\wamp\www\1204\t2.php 8 - 9 } Method [ <user> public method walk ] { @@ D:\wamp\www\1204\t2.php 11 - 12 } }}*/ echo $person->getName();//返回反射对象所属的类名 person echo $person->getFileName();//返回反射对象的类被定义时所处的文件路径 D:\wamp\www\1204\t2.php