clarkk
clarkk

Reputation: 27689

How to output/print methods with parameters in classes?

How is it possible to output methods in classes?

class Test {
    function wee($param1, $param2){
        return $param1.$param2;
    }
}

I want to output the method wee and all its content.. I also need to know the names and how many parameters the method requires

Upvotes: 2

Views: 56

Answers (1)

Mihai Iorga
Mihai Iorga

Reputation: 39704

Use ReflectionClass

$class = new ReflectionClass('Test');
$methods = $class->getMethods();
$parameters = $class->getMethod('wee')->getParameters();
var_dump($methods);
var_dump($parameters);

or a more stylized output

echo "<pre>";
$class = new ReflectionClass('Test');
$methods = $class->getMethods();
foreach($methods as $name){
    echo $name;
}
echo "</pre>";

Upvotes: 6

Related Questions