jeudi 1 octobre 2015

Extract type hint from ReflectionParameter

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





Aucun commentaire:

Enregistrer un commentaire