PHP反射机制(二)

PHP5.* 反射API

ReflectionClass

反射类用于获取类的注释、属性、参数、方法、PHP扩展信息、修饰符等等(详细:官网文档)

example:



class Cup {
    public    $name;
    protected $big;
    private   $color;

    public function __construct($name, $big, $color)
    {
        $this->setName($name);
        $this->setAge($big);
        $this->setSex($color);
    }

    public function setName($name)
    {
        $this->name = $name;
    }

    protected function setBig($big)
    {
        $this->big = $big;
    }

    private function setSex($color)
    {
        $this->color = $color;
    }
}

$prodClass = new ReflectionClass('Cup');
$a = $prodClass->getmethod('setBig');
echo $a;

你可能感兴趣的:(php函数)