php 反射机制查看

1.查看类属性以及方法

single.php

class single
{
    private static $instance;
    public function __construct() {}
    /**@return single */
    public static function getInstance() {
        if(!isset(self::$instance)) {
            self::$instance = new single();
        }
        return self::$instance;
    }
    private function combine(){}
}

info.php

require_once('single.php');
$res = new ReflectionClass(single);
echo '<pre>';
print_r($res->getMethods());
print_r($res->getProperties());

结果

Array
(
    [0] => ReflectionMethod Object
        (
            [name] => __construct
            [class] => single
        )

    [1] => ReflectionMethod Object
        (
            [name] => getInstance
            [class] => single
        )

    [2] => ReflectionMethod Object
        (
            [name] => combine
            [class] => single
        )

)
Array
(
    [0] => ReflectionProperty Object
        (
            [name] => instance
            [class] => single
        )

)

如上返回single类的方法,属性

相关推荐