List all methods of a given class, excluding parent class's methods in PHP

前端 未结 4 1268
无人共我
无人共我 2021-02-14 03:51

I\'m building a unit testing framework for PHP and I was curious if there is a way to get a list of an objects methods which excludes the parent class\'s methods. So g

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-14 04:25

    Use ReflectionClass, for example:

    $f = new ReflectionClass('Bar');
    $methods = array();
    foreach ($f->getMethods() as $m) {
        if ($m->class == 'Bar') {
            $methods[] = $m->name;
        }
    }
    print_r($methods);
    

提交回复
热议问题