PHP反射機制(二)
阿新 • • 發佈:2019-01-09
PHP5.* 反射API
ReflectionClass
反射類用於獲取類的註釋、屬性、引數、方法、PHP擴充套件資訊、修飾符等等(詳細:官網文件)
example:
<?php
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;