Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:94391 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22151 invoked from network); 5 Jul 2016 15:38:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jul 2016 15:38:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.178 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.161.178 mail-yw0-f178.google.com Received: from [209.85.161.178] ([209.85.161.178:33058] helo=mail-yw0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 40/80-19446-B64DB775 for ; Tue, 05 Jul 2016 11:38:19 -0400 Received: by mail-yw0-f178.google.com with SMTP id v77so64645679ywg.0 for ; Tue, 05 Jul 2016 08:38:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=p4gSSU6PmaLx028K0qB6BqYIx5HUa7GR0TBRZbToy9I=; b=aSxG/i2FHR0XyUu9NAYoFZAqy4YFJf85+x7qmPftofUk3VyaNLnhCQeU9FQ63lvomT z5uX5QBhMxcdnVjSt44tAQ8W9BEZ1YI3JnzR1kdLXkMez2u8wXisSEcdTvpUwRKe06QC uD5dadxYLNfq1OwpGPm3Zw4NDqikhhWN03FC2/Fzsq9E5pbKUYdW7034Pg5oaUqgKEof wO6OTQElVu1VBQ5TSMNumHbaEt4mDBwvdaNr45HHgfGaXcVR/Z/4ZO8AbqyHruQzvWJv rj7tChPtOTPFwEsiyTXAlq9eRCBG1SviM58PLeFNsS41gigJxoZRsHgWNypm8G/PJSWd WgNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=p4gSSU6PmaLx028K0qB6BqYIx5HUa7GR0TBRZbToy9I=; b=IBzm859Te1S+4zR3c7T0lAMt6CHbQBVPzgKe67u88TICaV2fCCZNndMjxNlDYtCGU4 JylNiD846KtqbFHGMkuJGeJyRkajhPaFp5JzZL9T87Jo2jJ+DIHCQ91e6Qupx+8okfba rd9sssGrTFar2818ef6MwzE+QKfxfqphklJk8h6mQvuX5utooAifzcM9KgUOj4C0ntjD W+EohLDg5eYlkKLYujP2WbDZyvr31St1Vcrp5UqK+Hvck4PV0ryGENXkDGNxgbKGUKtt nJGH0Yh9XoQypHblk3HBO9kNSl5UUjdmVOEyLovZ/25NbMvR7/4rcyLz3T0jiKNOGIHO 9KJw== X-Gm-Message-State: ALyK8tJp3xGPdJzdX5VUKJvXdB0SNhBwlVzAERnvtgAYE25STZPaoEcOCYV57nHenwBhBzvlFf1y1Ryq0zqrXg== X-Received: by 10.37.197.13 with SMTP id v13mr10898493ybe.46.1467733096735; Tue, 05 Jul 2016 08:38:16 -0700 (PDT) MIME-Version: 1.0 Received: by 10.13.219.203 with HTTP; Tue, 5 Jul 2016 08:38:16 -0700 (PDT) In-Reply-To: References: <1f39f97a-6aaf-8550-9f82-a7e80465f903@telia.com> Date: Tue, 5 Jul 2016 17:38:16 +0200 Message-ID: To: Levi Morrison Cc: =?UTF-8?Q?Bj=C3=B6rn_Larsson?= , PHP internals Content-Type: multipart/alternative; boundary=94eb2c147ba2db2bcb0536e53d22 Subject: Re: [PHP-DEV] [RFC][Vote] ReflectionType Improvements From: nikita.ppv@gmail.com (Nikita Popov) --94eb2c147ba2db2bcb0536e53d22 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Tue, Jul 5, 2016 at 3:21 PM, Levi Morrison wrote: > On Mon, Jul 4, 2016 at 10:51 AM, Bj=C3=B6rn 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 b= ut > >>> 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 wil= l > >> 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 sur= e > >> that this will lead to broken code: For example, people will try to us= e > >> "$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 onl= y > >> functionality that ReflectionClassType provides), and if necessary thi= s > >> 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=C3=B6rn 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'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 =3D $type->getClass(); > } > // and > if (class_exists($type->getName())) { > $r =3D 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 =3D new ReflectionClass($type->getName()); > } > > 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. > > I hope people who voted no will share why they have done so, but I > also hope they'll switch to yes if they voted no because they don't > see it as being useful. > To add to this, another issue we discussed OTR but didn't really come to a conclusion on, is the handling of self and parent type hints by ReflectionClassType. On the one hand, ReflectionClassType can be advantageous here, because it can resolve self/parent itself and return the appropriate ReflectionClass. Otherwise the user would have to do this themselves (if getting a ReflectionClass is a goal). On the other hand, self/parent are not always statically resolvable. For methods in traits self does not refer to the trait, but rather to the class the trait will be used in. This means that when reflecting on a self type on a trait you wouldn't get a ReflectionClassType (for something that is clearly a class type hint). A similar issue also exists for self/parent on closures. Regards, Nikita --94eb2c147ba2db2bcb0536e53d22--