Re: [RFC][DISCUSSION] ReflectionParameter::getClassName()
| From: | Matteo Beccati | Date: | Mon, 16 Mar 2015 16:33:13 +0000 |
| Subject: | Re: [RFC][DISCUSSION] ReflectionParameter::getClassName() | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85073@lists.php.net to get a copy of this message | ||
Hi everyone,
I know it's late for the RFC party, but it looks like some form of STH is going to land in PHP7. Without reflection support, which is also missing from return types as far as I know.
That's why I'm resuming this thread, as I still think this is the best approach. Many do not like ReflectionTypeAnnotation, but that's a trivial change, if we can agree that the behaviour is correct.
Cheers
On 15/02/2015 10:28, Matteo Beccati wrote:
Hi, On 14/02/2015 21:23, Matteo Beccati wrote:-- Matteo Beccati Development & Consulting - http://www.beccati.com/On 14/02/2015 16:34, Philip Sturgeon wrote: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()) {On Sat, Jan 31, 2015 at 8:27 PM, Andrea Faulds <ajf@ajf.me> 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.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$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