php 反射机制查看

in 系统环境
关注公众号【好便宜】( ID:haopianyi222 ),领红包啦~
阿里云,国内最大的云服务商,注册就送数千元优惠券:https://t.cn/AiQe5A0g
腾讯云,良心云,价格优惠: https://t.cn/AieHwwKl
搬瓦工,CN2 GIA 优质线路,搭梯子、海外建站推荐: https://t.cn/AieHwfX9

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类的方法,属性

关注公众号【好便宜】( ID:haopianyi222 ),领红包啦~
阿里云,国内最大的云服务商,注册就送数千元优惠券:https://t.cn/AiQe5A0g
腾讯云,良心云,价格优惠: https://t.cn/AieHwwKl
搬瓦工,CN2 GIA 优质线路,搭梯子、海外建站推荐: https://t.cn/AieHwfX9
扫一扫关注公众号添加购物返利助手,领红包
Comments are closed.