Re: [RFC][DISCUSSION] ReflectionParameter::getClassName()

From: Date: Sun, 15 Feb 2015 09:28:16 +0000
Subject: Re: [RFC][DISCUSSION] ReflectionParameter::getClassName()
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi,

On 14/02/2015 21:23, Matteo Beccati wrote:
On 14/02/2015 16:34, Philip Sturgeon wrote:
On Sat, Jan 31, 2015 at 8:27 PM, Andrea Faulds <[email protected]> wrote:
I think the more important issue is the conflict with the ReflectionTypeAnnotation RFC, which proposes something similar to what was originally part of the Return Types RFC: https://wiki.php.net/rfc/reflectionparameter.typehint
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)

« previous php.internals (#82716) next »