Created
January 17, 2012 22:11
-
-
Save jessevondoom/1629322 to your computer and use it in GitHub Desktop.
Enumerate class/methods/parameters in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$class_name = 'AdminHelper'; | |
echo $class_name . ' Class:<br />'; | |
$c = new ReflectionClass($class_name); | |
$methods = $c->getMethods(); | |
echo '<ul>'; | |
foreach ($methods as $method) { | |
echo '<li>' . $method->getName() . '</li>'; | |
$m = new ReflectionMethod($class_name, $method->getName()); | |
$params = $m->getParameters(); | |
echo '<ul>'; | |
foreach ($params as $param) { | |
//$param is an instance of ReflectionParameter | |
echo '<li>' . $param->getName() . ': '; | |
if ($param->isOptional()) { | |
echo 'optional (' . print_r($param->getDefaultValue(),true) . ')<br />'; | |
} else { | |
echo '<b>required</b><br />'; | |
} | |
echo '</li>'; | |
} | |
echo '</ul>'; | |
} | |
echo '</ul>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment