Skip to content

Instantly share code, notes, and snippets.

@jwpage
Created February 3, 2013 12:38
Show Gist options
  • Save jwpage/4701622 to your computer and use it in GitHub Desktop.
Save jwpage/4701622 to your computer and use it in GitHub Desktop.
Script to output the public method signatures for a class.
<?php
$class = new ReflectionClass('MY_CLASS');
$methods = $class->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
$signature = implode(' ', Reflection::getModifierNames($method->getModifiers()));
$signature.= ' function';
$signature.= ' '.$method->getName().' (';
$args = $method->getParameters();
foreach ($args as $arg) {
$signature .= $arg->isArray() ? 'array ' : '';
$signature .= '$'.$arg->getName();
if ($arg->isDefaultValueAvailable()) {
$var = trim(var_export($arg->getDefaultValue(), true));
$signature .= ' = '.((ctype_alpha($var)) ? strtolower($var) : str_replace("\n", '', $var));
}
$signature .= ', ';
}
$signature = rtrim($signature, ', ');
$signature .= ');';
echo " ".$signature."\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment