<?php
class Person
{
public $name;
private $age;
protected $hobbies = [];
public function sleep(){
return '';
}
protected function eat(){
return '';
}
private function play_game(){
return '';
}
}
$person = new Person();
$method = new ReflectionClass($person);
$res = $method->getMethods();
echo "<pre/>";
print_r($res);
/*Array
(
[0] => ReflectionMethod Object
(
[name] => sleep
[class] => Person
)
[1] => ReflectionMethod Object
(
[name] => eat
[class] => Person
)
[2] => ReflectionMethod Object
(
[name] => play_game
[class] => Person
)
)*/
?>
PHP利用反射感知类中成员方法
最新推荐文章于 2021-03-22 06:20:32 发布