Skip to content

Instantly share code, notes, and snippets.

@phpdreams
Created January 15, 2016 07:39
Show Gist options
  • Save phpdreams/f2a70b425bb558557974 to your computer and use it in GitHub Desktop.
Save phpdreams/f2a70b425bb558557974 to your computer and use it in GitHub Desktop.
PHP snippet to extract the methods and parameters from a class you can't otherwise access.
<?php
/**
* Snippet to extract information about a class you don't have access to.
*/
$extractClass = $GLOBALS['someclass'];
$className = get_class( $extractClass );
$classMethods = get_class_methods( $extractClass );
echo "Class: $className\n";
echo "---------------------------------\n\n";
foreach($classMethods as $method) {
$r = new ReflectionMethod($className, $method);
if($r->isPrivate()) echo 'private ';
if($r->isProtected()) echo 'protected ';
if($r->isPublic()) echo 'public ';
echo $method.'( ';
$params = $r->getParameters();
foreach ($params as $param) {
//$param is an instance of ReflectionParameter
$argument = '$'.$param->getName();
if($param->isOptional()) $argument .= ' = null';
$argArray[] = $argument;
}
$argList = @implode(', ', $argArray);
unset($argArray);
echo $argList." );\n";
echo "--\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment