Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126773 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 3DB3C1A00C3 for ; Fri, 14 Mar 2025 23:37:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1741995302; bh=POevSpRld0Dtu5wUc89Zlf8s6dYqv5UNiIRF3Bc9AGc=; h=Date:From:To:In-Reply-To:References:Subject:From; b=VkKvyZXAfTT8HrPZbx7N3y23DQy1dNgfagfS5egQWD16zPP6fSPhH9piABdU5qLmL LUiSXUeu5DbR81uQ+a16nLe7Zj5C98AmEPvxwa60O3+L3lqV5pVF0JlvzP8jbwuM7Y ZwngpJJpb4eM96T2aOHmsBe4k95ZabpWhjC1qXFRg/IARIffSs7wG28j21shq7jxG6 3gC6c5XBILGnhWP7h7s52ybyrZZ1DhFtL4UP7GobR4hOxih05cVb0/my6bcF+LU7Vq gLvuOXUYtM8z+qpkAZNDvMsdDdJ9Vs8MuhfRD+iRYghnetnN/YQV/bABFq8KYEjuFI YbXGzWCb0DJVQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 452631801EE for ; Fri, 14 Mar 2025 23:34:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 14 Mar 2025 23:34:57 +0000 (UTC) Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfout.phl.internal (Postfix) with ESMTP id EDD571382827; Fri, 14 Mar 2025 19:37:29 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-11.internal (MEProxy); Fri, 14 Mar 2025 19:37:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1741995449; x=1742081849; bh=kqatsk22Fw 9xtGGP4jvvYpiijJB4zGydI2PmJD4lksA=; b=AShDZ0an8XVKf5PJVChOuJJX/M vZf3rpCjxNMaJz1893NSn6i06RMQd/4zT8pXBRvHHruuevX5vssIQpmoPhbXMZNv Zzu9G/N+GX8vN6cf4/e6dXvhpW8xJ9hqUlokyjeZYbo4K5QxcD0NwY/zgS46hruu CH3rCWFf4v2YiPIc0kgis5IYf25rkc4sLbIcpBfzB8AYczPM56A8El76hlLf6cGu V2diBSB5CWOSI4W19RlTqotwRsyb6mYmSIDgIpMYueKQHNBEJ+UEjIhCCEBIhm5A PcXrcdiUELq1cryE7LmV0hXVpjsxbzqR6JGcmn+vbevk5stuMfvTRDzUtjjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1741995449; x=1742081849; bh=kqatsk22Fw9xtGGP4jvvYpiijJB4zGydI2P mJD4lksA=; b=YQEuZE7f8HwjLvZZ0/+5F2lWIokZBwSkyX9IqiSKeAfvVa3ESAj Dd69GlFlJHGaw7wrax7CF7bZRZdcDdL4CSsg90bTgNIz/sHKsS4rrv4hWBLuow7h 0mSyBuZ8Vd0qvoE21uY4b8fMrxapCb31LR60GsQmrbi9uIUGHh2lFQsTuMzuRc7w 49Edvc8HcW9Fj1A75OsHi4XK8xu4ZNSIHInnPmew4kSPIFrmjy5tnyS5NZBQAZAb uUZdOu/iKLWSx8G0veHNnya0MSYUO6+ZzZT2UsY1x+uSCUAFNcc2U68L83UkM8J6 3O0EK+HPjvRDlSzQhXIUeUhyYrbJd1Ab1Nw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddufedvudejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvffkjghfufgtsegrtderreertdej necuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdrtg houggvsheqnecuggftrfgrthhtvghrnhepheeiffekteeljeeufeejffeuffehvedugfet veefieejveffhffhgeeuteetffelnecuffhomhgrihhnpehphhhprdhnvghtpdhgihhthh husgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhr ohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgtphhtthhopedvpdhmoh guvgepshhmthhpohhuthdprhgtphhtthhopegsohgsfigvihelsehhohhtmhgrihhlrdgt ohhmpdhrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 9FC99780068; Fri, 14 Mar 2025 19:37:28 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Sat, 15 Mar 2025 00:37:08 +0100 To: "Bob Weinand" , internals@lists.php.net Message-ID: <4abd7008-ae33-46fe-8bbd-7c99f7c48158@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] RFC: short and inner classes Content-Type: multipart/alternative; boundary=0cf008fb32ca467c8310d9712e1837c0 From: rob@bottled.codes ("Rob Landers") --0cf008fb32ca467c8310d9712e1837c0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Fri, Mar 14, 2025, at 19:16, Bob Weinand wrote: > Hey Rob, >=20 > On 6.3.2025 00:11:22, Rob Landers wrote: >> Hello PHP Internals, >>=20 >> I'd like to introduce my RFC for discussion: https://wiki.php.net/rfc= /short-and-inner-classes > A small note on the Reflection section: it should include a method giv= ing you an array of all contained ReflectionClasses: $reflection->getInn= erClasses() >=20 > And likely also a method to get an inner class by name $reflection->ge= tInnerClass("Foo"). >=20 >=20 >=20 > Bob >=20 Classes don't actually know their inner classes -- they aren't like prop= erties. In essence, an inner class is just a regular class with a funny = name and access to scopes it wouldn't normally have access to. We could = probably add `getOuterClass(): string` if that is useful. It is possible= to keep track of a class's inner classes, but then that introduces a pa= radox chicken/egg type problem during construction, which may or may not= be a problem. On Fri, Mar 14, 2025, at 22:08, Rowan Tommins [IMSoP] wrote: > The other thing I wonder is whether the original reason why `::` wasn'= t=20 > used as the namespace separator still applies, and needs to be account= ed=20 > for here? >=20 > --=20 > Rowan Tommins > [IMSoP] >=20 I'm replying to you Rowan, but also to the whole conversation on the top= ic of separating inner classes. I was going to add this example to the R= FC: https://gist.github.com/withinboredom/c007e35d3b042b87b02ac550db589a= 0c, but I decided to get food poisoning for the last few hours instead. = :joy: Where using it looks like this: $user =3D new User:>Builder("Rob")->withEmail("rob@bottled.codes")->buil= d(); The user builder is intrinsically tied to the User class itself, it isn'= t just a namespace. The user builder shares scope with the user class an= d is able to be the only way to construct a user (barring reflection). S= o, I'm inclined to agree with Bob here: > Inner classes are supposed to be intrinsically tied to their containin= g class, and making it work like a namespace reduces the association a l= ot. Furthermore, I'm relatively certain this approach can be slightly modifi= ed to support "namespace private/protected" classes, in general. So, tha= t will also possibly be a follow-up RFC and having them mixed up will co= mplicate things. In any case, I am not a fan of using the namespace sepa= rator here. I could get behind `::`, but I feel that it introduces human ambiguity. = I don't believe it would introduce compiler ambiguity, but as a human, I= have to hope the programmers are using a style that makes it obvious wh= at are inner classes and what are constants/methods. I don't know, I keep coming back to `:>` ... it isn't perfect, and it is= somewhat annoying to type, but I don't have anything better. =E2=80=94 Rob --0cf008fb32ca467c8310d9712e1837c0 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Fri, Mar = 14, 2025, at 19:16, Bob Weinand wrote:

Hey Rob,

On 6.3.2025 00:11:22, Rob Landers=0A wrote:
Hello PHP Internals,

I'd li= ke to introduce my RFC for discussion: http= s://wiki.php.net/rfc/short-and-inner-classes
<= p>A small note on the Reflection section: it should include a=0A me= thod giving you an array of all contained ReflectionClasses:=0A $re= flection->getInnerClasses()

And likely also a method to get= an inner class by name=0A $reflection->getInnerClass("Foo").


Bob


Classes d= on't actually know their inner classes -- they aren't like properties. I= n essence, an inner class is just a regular class with a funny name and = access to scopes it wouldn't normally have access to. We could probably = add `getOuterClass(): string` if that is useful. It is possible to keep = track of a class's inner classes, but then that introduces a paradox chi= cken/egg type problem during construction, which may or may not be a pro= blem.

On Fri, Mar 14, 2025, at 22:08, Rowan= Tommins [IMSoP] wrote:
The other thing I wonder is whether the original reason why= `::` wasn't 
used as the namespace separator still a= pplies, and needs to be accounted 
for here?

-- 
Rowan Tommins
= [IMSoP]


I'm rep= lying to you Rowan, but also to the whole conversation on the topic of s= eparating inner classes. I was going to add this example to the RFC:&nbs= p;https://gist.github.com/withinboredom/c007e35d3b042b87b02ac= 550db589a0c, but I decided to get food poisoning for the last few ho= urs instead. :joy:

Where using it looks lik= e this:

$user =3D new User:>Builder("Rob= ")->withEmail("rob@bottled.codes= ")->build();

The user builder is int= rinsically tied to the User class itself, it isn't just a namespace. The= user builder shares scope with the user class and is able to be the onl= y way to construct a user (barring reflection). So, I'm inclined to agre= e with Bob here:

= Inner= classes are supposed to be intrinsically tied to their containing class= , and making it work like a namespace reduces the association a lot.

Furthermore, I'm relativel= y certain this approach can be slightly modified to support "namespace p= rivate/protected" classes, in general. So, that will also possibly be a = follow-up RFC and having them mixed up will complicate things. In any ca= se, I am not a fan of using the namespace separator here.
=
I could get behind `::`, but I feel that it introduces hu= man ambiguity. I don't believe it would introduce compiler ambiguity, bu= t as a human, I have to hope the programmers are using a style that make= s it obvious what are inner classes and what are constants/methods.
<= /div>

I don't know, I keep coming back to `:>` ...= it isn't perfect, and it is somewhat annoying to type, but I don't have= anything better.

=E2=80= =94 Rob
--0cf008fb32ca467c8310d9712e1837c0--