Created
January 15, 2016 07:39
-
-
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.
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 | |
/** | |
* 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