Skip to content

Instantly share code, notes, and snippets.

@andredublin
Created December 26, 2011 22:10
Show Gist options
  • Save andredublin/1522191 to your computer and use it in GitHub Desktop.
Save andredublin/1522191 to your computer and use it in GitHub Desktop.
Investigate method arguments with PHP Reflection API
$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