Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82716 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12674 invoked from network); 15 Feb 2015 09:28:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Feb 2015 09:28:31 -0000 Authentication-Results: pb1.pair.com header.from=php@beccati.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=php@beccati.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain beccati.com designates 176.9.114.167 as permitted sender) X-PHP-List-Original-Sender: php@beccati.com X-Host-Fingerprint: 176.9.114.167 spritz.beccati.com Received: from [176.9.114.167] ([176.9.114.167:42100] helo=mail.beccati.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/40-06835-CB660E45 for ; Sun, 15 Feb 2015 04:28:29 -0500 Received: (qmail 22598 invoked from network); 15 Feb 2015 09:28:24 -0000 Received: from home.beccati.com (HELO ?192.168.1.202?) (88.149.176.119) by mail.beccati.com with SMTP; 15 Feb 2015 09:28:24 -0000 Message-ID: <54E066B0.1040501@beccati.com> Date: Sun, 15 Feb 2015 10:28:16 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Philip Sturgeon CC: "internals@lists.php.net" , Andrea Faulds , Sara Golemon References: <54CC8E81.3020104@beccati.com> <746466D2-F3DB-4561-8C78-8685CC8F7EE7@ajf.me> <54DFAEC6.2050903@beccati.com> In-Reply-To: <54DFAEC6.2050903@beccati.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][DISCUSSION] ReflectionParameter::getClassName() From: php@beccati.com (Matteo Beccati) 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 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/