class C
{
function methodA(Exception $a, array $id){}
}
function getClassName(ReflectionParameter $param) {
$regex = '/\[([^\]]*)\]/';
preg_match($regex, $param->__toString(), $matches);
return isset($matches[1]) ? $matches[1] : null;
}
foreach( new ReflectionMethod('C', 'methodA')->getParameters() as $param)
{
echo getClassName($param);
}
Want returned value to simply be 'Exception' and 'array' not "Exception $a" and "array $id". What should the regex be. Working on php 5.3
Just use the Reflection classes
foreach( (new ReflectionMethod('C', 'methodA'))->getParameters() as $param)
{
$class = $param->getClass();
if ($class) {
echo $class->getName()."
";
} elseif ($param->isArray()) {
echo "array
";
} else {
echo "unknown
";
}
}