Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94389 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19926 invoked from network); 5 Jul 2016 15:30:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jul 2016 15:30:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.17.22 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.17.22 mout.gmx.net Received: from [212.227.17.22] ([212.227.17.22:63819] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/00-19446-382DB775 for ; Tue, 05 Jul 2016 11:30:12 -0400 Received: from [192.168.2.103] ([217.82.227.154]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0M6fXs-1bYXGc363Q-00wW4z; Tue, 05 Jul 2016 17:30:06 +0200 To: Levi Morrison , =?UTF-8?Q?Bj=c3=b6rn_Larsson?= References: <1f39f97a-6aaf-8550-9f82-a7e80465f903@telia.com> Cc: Nikita Popov , PHP internals Message-ID: <13e40d6f-c63c-6d0b-db09-7f5805ed018c@gmx.de> Date: Tue, 5 Jul 2016 17:30:06 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:CMvcStEwugLv8u2op2XhecMXjqaDBypyroO1wU2MNyT2q2k7WVL jlA5HbQLxoNnV6u3x+oNiY1sdXJnrQi0635V27ls9r8qzcNqbsszJGmsnPeVcuRwOo1x0Jp CUL43Z8QIuulNgDdr8WGL68r6GVYVupuMGXHjlZkkFIz6pEQK6XxMb9eKs2BFXniGITGyuF oBEUDc+51oDE00GeiEaoQ== X-UI-Out-Filterresults: notjunk:1;V01:K0:rDSwdkoF3Y4=:XjGjkkCd575qfPrbwxWRwj KJTv5Rgs3YrdeYwPp0lCbSZP5SSMVa+0pil5rv/YO+rsEIYGAlKtjm+2ozHszVMhfRYXLjvcF QsDfDjQ4stQZ7riKeYFiMaQDO+1EGkbFz3WgKoOFgOkIQGswlERHXrzqvw9HShqumAE97/uf1 VkW7Jr6uwr8Eg3gI2cuFQ05hKrspN3BIKGjGcZpjHIImvoXMK6xvgbDyb1ERqqg6x4VXHbtnM ueWvL4FWiEkSWE/fYmgUlN97d4Fy/6i/Wr5E+XCMhCL7zfJgxJ6aFGmbzENR6s0VbLkTMP8kT JemzKu3ONgJLghuuSRo31WhHVseWzySXDFbKiciLnLzn6N1EN74AeSWwxrFDOwJgWdeCw1Bh6 KHADn5U8wBd/3EZEUP8rHCg87LyCb1G23r7nwPW4i5A1RiPSPahohIAY+piJ02yF8htttYQ9m cORqpLKHeAPBbkx8jJts2d7jRmYbHNlR6t3IePuFCKQAd7sFMVzdK+QW1U3n4h5o6e3tyVs9h Ox/UUNINu3bpUABcO9xv+hkltJLjHsn4pW75evk9pbkuXQKQXuJ/IJGcvcNu4jJ6nIUyFZh87 LYPiZGJ27x74YFLnWHjkp8F1leH+8wvc2es29DP58dzePP0ro/gjF09zJN4++pNElnkK95A1R nW6onanIFkInimle9Vqa5BDR7ndWNtmqE46rM4Z1txezejXGkeENS99rmYHdxwGA54LUHelAP JwFjOniwrC/1U787acMczpuhCVRfNKc5hkBksf2n/l9QYUgiN2i75o8C1a8HNvJBN5zy0LL4z K4c5LMp Subject: Re: [PHP-DEV] [RFC][Vote] ReflectionType Improvements From: cmbecker69@gmx.de (Christoph Becker) On 05.07.2016 at 15:21, Levi Morrison wrote: > On Mon, Jul 4, 2016 at 10:51 AM, Björn Larsson > wrote: >> Den 2016-06-30 kl. 23:57, skrev Nikita Popov: >>> >>> On Thu, Jun 30, 2016 at 6:06 PM, Levi Morrison wrote: >>> >>>> The RFC for improving ReflectionType[1] is now in voting phase. The >>>> voting >>>> window is June 30th through July 8th. I have not finished the patch but >>>> I'll have it done before the end of voting. >>>> >>>> [1]: https://wiki.php.net/rfc/ReflectionTypeImprovements >>> >>> >>> Replying on-list as multiple people asked: >>> >>> I'm voting against this RFC, because it introduced not only the >>> ReflectionNamedType class (which is reasonable), but also the >>> ReflectionClassType class (which is not). >>> >>> My main objection to ReflectionClassType is that it is autoloading >>> dependent (*). Something like getReturnType() on a class type hint will >>> either return a ReflectionClassType if the class can be loaded, or a >>> ReflectionNamedType if it can't. I think this is confusing and I'm sure >>> that this will lead to broken code: For example, people will try to use >>> "$type instanceof ReflectionClassType" to check whether something is a >>> class type hint, while the currently correct way, which works >>> independently >>> of class loading, is to check isBuiltin() instead. >>> >>> I don't think that most consumers of ReflectionType are interested in >>> obtaining a ReflectionClass for the type hint anyway (which is the only >>> functionality that ReflectionClassType provides), and if necessary this >>> can >>> be easily done in userland. There is no need to over-complicate the >>> ReflectionType functionality in this manner, especially with the proposed >>> semantics. >>> >>> Nikita >>> >> Maybe one should split the vote into separate for each function. >> I mean pity if vote fails because one function is not attractive while >> the other one is... >> >> What do you think? >> >> Regards //Björn Larsson > > I think that it's disappointing that I received no feedback on this > RFC at all and yet have this ratio of votes in the negative. I have not yet voted, but I tend to be -1 on this RFC. > I'll take this opportunity to share a portion of a conversation I had > with Nikita that demonstrates why ReflectionClassType is actually > useful: > >> Nikita: But does it really help them? I don't see a lot of differences between these two: > if ($type instanceof ReflectionClassType) { > $r = $type->getClass(); > } > // and > if (class_exists($type->getName())) { > $r = new ReflectionClass($type->getName()); > } >> Levi: ...[I]t will fail for interfaces.] ReflectionClass can be built for those but class_exists() will be false. >> Nikita: True :) > > The (currently) correct code would be: > > if (class_exists($type->getName()) || interface_exists($type->getName())) { > $r = new ReflectionClass($type->getName()); > } ACK. If this code is regarded as too verbose, a function class_or_interface_exists() (or something like that) can easily be defined in userland. Anyhow, using (class|interface)_exists() offers the option to use autoloading or not, contrary to the RFC which always uses autoloading, what might not be desired. > But if we add some other type such as enums we may have to add more > conditions. As long as ReflectionClass can be made from the type then > doing it in the engine is fully forward compatible. Iff we add some other type, we can always reconsider to add another subclass. In my opinion, it doesn't make sense to introduce complexity (albeit minor in this case) to cater to potential future changes. Another (minor) issue I have with the RFC is the introduction of ReflectionNamedType. A simpler alternative appears to be to add the getName() method to ReflectionType; for unnamed types this could simply return (string) $reflectionType. That might not be the most farsighted design decision, though. -- Christoph M. Becker