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

class, methods, oop, php

Solution

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);

Problem

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 given this: ``` class Foo { public function doSomethingFooey() { echo 'HELLO THERE!'; } } class Bar extends Foo { public function goToTheBar() { // DRINK! } } ``` I want a function which will, given the parameter `new Bar()` return: ``` array( 'goToTheBar' ); ``` WITHOUT needing to instantiate an instance of Foo. (This means `get_class_methods` will not work).

Original source