Skip to content

Instantly share code, notes, and snippets.

@scintill
Created June 20, 2014 23:39
Show Gist options
  • Save scintill/841e8643112bd1fb38a0 to your computer and use it in GitHub Desktop.
Save scintill/841e8643112bd1fb38a0 to your computer and use it in GitHub Desktop.
<?php
/**
* Extract an interface definition from an existing class.
*
* Found while cleaning up old files -- I am only assuming it works. :)
*/
$class = new ReflectionClass($className);
foreach ($class->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC) as $method) {
if ($method->isPublic()) echo 'public ';
if ($method->isStatic()) echo 'static ';
echo 'function ', $method->getName(), '(';
foreach ($method->getParameters() as $i => $param) {
if ($i) {
echo ', ';
}
if ($param->isArray()) {
echo 'array ';
}
echo '$', $param->getName();
if ($param->isDefaultValueAvailable()) {
echo ' = ', var_export($param->getDefaultValue(), true);
}
}
echo ");\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment