Created
December 26, 2011 22:10
-
-
Save andredublin/1522191 to your computer and use it in GitHub Desktop.
Investigate method arguments with PHP Reflection API
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
$my_class = new ReflectionClass('MyClass'); | |
$method = $my_class->getMethod("__construct"); | |
$params = $method->getParameters(); | |
foreach ($params as $param) | |
{ | |
print argData($param); | |
} | |
function argData(ReflectionParameter $arg) | |
{ | |
$details = ""; | |
$name = $arg->getName(); | |
$class = $arg->getClass(); | |
if (! empty($class)) | |
{ | |
$classname = $class->getName(); | |
$details .= "\$$name must be a $classname object\n"; | |
} | |
if ($arg->isPassedByReference()) | |
{ | |
$details .= "\$$name is passed by reference\n"; | |
} | |
return $details; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment