Re: [RFC][DISCUSSION] ReflectionParameter::getClassName()
Hi,
On 14/02/2015 21:23, Matteo Beccati wrote:
On 14/02/2015 16:34, Philip Sturgeon wrote:
That's the "reflection support" I was talking about! I knew there was
something, but I just couldn't find it in the RFCs themself.
I've been playing a little bit with Sara's work (as you might have
noticed if you follow php-cvs - sorry again!) and got it working with
the scalar type hints branch:
https://github.com/mbeccati/php-src/tree/scalar_hints_with_reflection
It's still missing the scalar part and possibly an easy way to get the
class name as Phil suggests.
Thanks to my cats waking me up too early on a sunday morning, I've rebased Sara's patch to current master and updated it to support return types:
https://github.com/mbeccati/php-src/commits/reflection.typehint
The new methods are:
* ReflectionFunctionAbstract::hasReturnTypeAnnotation()
* ReflectionFunctionAbstract::getReturnTypeAnnotation()
* ReflectionTypeAnnotation::isInstance()
The latter should fulfil Phil's getClassName() purpose, albeit it's much more verbose:
function get_name (ReflectionParameter $rp) {
if ($rp->hasTypeAnnotation()) {
$ra = $rp->getTypeAnnotation();
if ($ra->isInstance()) {
return (string) $ra;
}
}
}
I've also added scalar support in:
https://github.com/mbeccati/php-src/commits/scalar_hints_with_reflection
which has:
* ReflectionTypeAnnotation::isScalar()
I believe that both isInstance/isScalar would probably apply to ReflectionParameter too, unless the "old way" is supposed to be deprecated.
@Phil I apologise it I hijacked your RFC, but I think that having just ReflectionParameter::getClassName() falls a bit short IMHO, especially with return types.
@Andrea, @Sara I hope you don't mind ;)
Cheers
--
Matteo Beccati
Development & Consulting - http://www.beccati.com/
Thread (10 messages)