Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127168 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 5C2671AE461 for ; Tue, 22 Apr 2025 17:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1745342974; bh=9okZOMquqK4AxNLIYj81UeohV7W/VchbFDRS2q8696k=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=l1Ua8Nkp0FYnR5dVu4IiqUoM9+7K7ojVAX3mjOVP+iZl+5gVsvsrJrDwDR3zQZyJr +VJe8hYScjDW51MIhxZCXVuZzqORjIAjuL49qwadwMsss0eh+XNAq2MMsB/a6dEQa5 eoCgAH7u0VPibonhcwYAOPLjKq5C/SsMOKtIGktuxM3PSr2dPSAm3KzIhurxjvCyOE VBM1K8DdKzA3uOtVTHJBNVBn1p9Au0qTtyk2DcpjXaFbr1qZeukf/4QpPH7ynaZM02 S/Dn3RiOHgK2QzMPI25Y62dcXhh4SFEzfWkgqclwBA5P8lqz7oyPx77NhaSTSc5LuU +YryM0B3a9xSA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A12891801D4 for ; Tue, 22 Apr 2025 17:29:31 +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: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 22 Apr 2025 17:28:17 +0000 (UTC) Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id 7BFA013803F5; Tue, 22 Apr 2025 13:30:36 -0400 (EDT) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-05.internal (MEProxy); Tue, 22 Apr 2025 13:30:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc: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=fm3; t=1745343036; x= 1745429436; bh=MF/F7SngOwknuH4/JJbkSINtHMiudljT2o2up97hPdI=; b=P sFGJnV2l5WVl2QqWxo5VMHKgqxGh3vT8s+0jK1aSpS2YDXUfIss7AkGnNPRVfyCS TkwshONRp32R+KvSrakgwXhRUXT9bQjpXj4t1vlW8xUtr07jWQg1GZCHwD7JHFmZ qZKqnYbOCITuMYyVpZj77s5GXtyR9JZ5y02YdARLFi+PRJQDo8EJN2XJZLyHTX4c oRhtQCb51Xf1wdehWA0VAdG1XkDYLzd6ex8s8T4cbhzRXyYqDpbBfBIWTsRbpC/n Fi7+eIR9t6pnwhMmN8WDS2PkXwv2urtaQMui2qp2l8ohRrpqalsbsmT4Fh6efhLL 6c6vfGBPwYPf7iBsiTsxg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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=fm2; t= 1745343036; x=1745429436; bh=MF/F7SngOwknuH4/JJbkSINtHMiudljT2o2 up97hPdI=; b=wFDU9FfFi+XnmOpeseyXe+JjFB+FdiEN7lyj8aLuGwBiaEtuAgU i0a08tYvqyT6Lzv4uxfpi33sd9RwEnfsG3ze1ne88rWIjE1dddef2SR/ZUZCfkbr DxF9BerK+aOGztV33x/fjwWptzo8s0yYJz3SFmrOGif1c/KheGgmABG3910fvdLt 87dcH3BGtQZsw6B9H5dIKa65+ZJREPnQ5vserJI5bl+2owVx74r3a0AXeIqvkJub TMp7/x9vtsGJhSa9quTyVT+Z+RL/IYlXOm38ZBf5/jq07lJu86CVlxSlJIqWuEKq M9SNOsQdYYEVnKU/IIa79QQ+xe5IHp+LcSQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvgeegfeefucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhepofggfffhvfevkfgjfhfutgesrgdtreerredt jeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohhtthhlvggurd gtohguvghsqeenucggtffrrghtthgvrhhnpeeiueethedvvdefjefhgfeiheelheehtdfh feekjefflefgvedvkeduteejjedttdenucevlhhushhtvghrufhiiigvpedtnecurfgrrh grmhepmhgrihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghspdhnsggprhgt phhtthhopedvpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehlvghvihdrmhhorh hrihhsohhnsegurghtrgguohhghhhqrdgtohhmpdhrtghpthhtohepihhnthgvrhhnrghl sheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 0A01C780069; Tue, 22 Apr 2025 13:30:36 -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 X-ThreadId: T7acb3853146d671b Date: Tue, 22 Apr 2025 19:30:00 +0200 To: "Levi Morrison" Cc: internals@lists.php.net Message-ID: <8b13ef20-9139-4e72-8fd3-7d4c9dfc9a64@app.fastmail.com> In-Reply-To: References: <3e4ba7ea-a154-452d-abfc-05ef1322fade@app.fastmail.com> <782d76d9-711a-4cee-ae0e-fe0d69973f53@app.fastmail.com> <48dce917-d147-456b-9f03-c7e23411adff@app.fastmail.com> <8a16b81c-7dab-4523-a352-76ba0cb4e771@app.fastmail.com> <9c4ac301-dfb2-49da-90e5-37a2824fc4e3@app.fastmail.com> <5b1e6d70-a1c9-455c-93d3-6b22cf1fef11@app.fastmail.com> <52d84a5b-09d3-4e42-9620-a62fb239c21e@app.fastmail.com> <09a82882-f1ee-4bdb-8a27-e46144a711f1@app.fastmail.com> <706e22d7-94eb-44bd-a280-f629ba93b630@app.fastmail.com> <03a5b9a8-9fe1-4656-ab04-dd58669488b3@app.fastmail.com> Subject: Re: [PHP-DEV] Re: RFC: Nested Classes (was: short and inner classes) Content-Type: multipart/alternative; boundary=28927a586adf4e2f8236aad3c8c4cafb From: rob@bottled.codes ("Rob Landers") --28927a586adf4e2f8236aad3c8c4cafb Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Tue, Apr 22, 2025, at 19:22, Levi Morrison wrote: > On Sun, Apr 20, 2025 at 7:46=E2=80=AFAM Rob Landers wrote: > > > > On Mon, Mar 31, 2025, at 21:45, Rob Landers wrote: > > > > Hello internals, > > > > I have significantly revamped the RFC (again). Key changes to the RF= C: > > > > 1. More (realistic) examples, > > 2. Since enums are basically specialized classes, they are allowed t= o be nested as well (hat tip to Reddit), > > 3. Using backslash as the class separator, > > 4. Proper scoping (and shadowing), > > 5. Nesting is allowed in interfaces and enums as well as classes; bu= t not traits, > > 6. (Hopefully) Clearer wording, > > 7. Nesting in traits, or nested traits, are future scope, > > 8. Nested interfaces are future scope too. > > > > Some benefits of using \ as a separator: > > > > - a simple name can refer to nested classes: > > > > Scope resolution was expanded to treat inner classes within the same= class as =E2=80=9Cin scope.=E2=80=9D This provides a more natural usage: > > > > class Outer { > > class Inner {} > > public function foo(Inner $inner) {} > > } > > > > - Standard =E2=80=9Cuse=E2=80=9D statements can alias them: > > > > use Outer\Inner as Inner; > > > > But it also has some draw backs: > > > > - The engine doesn=E2=80=99t know that Outer\Inner is a nested class= and autoloaders will have to account for that. It will only ask for Out= er\Inner. > > > > - You cannot simply refer to parent:>Inner, you have to explicitly a= sk for the parent by name: SomeParentClass\Inner. > > > > A draft implementation (which is more of a proof-of-concept) is avai= lable on GitHub. > > > > > > Hello internals, > > > > As it seems that discussion has mostly died down, I'd like to put th= is towards a vote starting on May 1, 2025. > > > > =E2=80=94 Rob >=20 > I intend to vote no. Fundamentally, this proposal adds a form of > "packaging" which only affects classes. There's no packaging for > constants or functions, unless you put them onto a class to make them > class constants and static methods. This is weird to me. I would > prefer that we work out something more general. Thank you for your feedback! It very much isn't packaging, this is close= r to "friend" classes in C++ or nested classes in other languages (C#, K= otlin, Swift, Java, etc). I do intend to focus on packaging (in-general)= in the near future though. >=20 > I am also worried that naming collisions are possible. Something like = this: >=20 > ```php > namespace A { > class B {} > } >=20 > namespace { > class A { > class B {} > } > } > ``` >=20 > Where `A\B` refers to two possible things. I don't like this, and to > my knowledge, this type of confusion has not been possible in the > past. Of course, feel free to point it out if so. Note that methods > and properties of the same name are disambiguated by syntax, where > here the syntax is the same. >=20 I should update the RFC to include this case, thanks for pointing this o= ut. This would cause the ole' "Cannot redeclare class A\B" error. There = is not any ambiguity here. =E2=80=94 Rob --28927a586adf4e2f8236aad3c8c4cafb Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable


On Tue, Apr 22, 2025, at 19:22, Levi Morrison wrote:
On Sun, Apr 20, = 2025 at 7:46=E2=80=AFAM Rob Landers <rob@bottled.codes> wrote:
>
> On M= on, Mar 31, 2025, at 21:45, Rob Landers wrote:
>
= > Hello internals,
>
> I have significantly= revamped the RFC (again). Key changes to the RFC:
>
<= div>> 1. More (realistic) examples,
> 2. Since enums are= basically specialized classes, they are allowed to be nested as well (h= at tip to Reddit),
> 3. Using backslash as the class separa= tor,
> 4. Proper scoping (and shadowing),
> 5.= Nesting is allowed in interfaces and enums as well as classes; but not = traits,
> 6. (Hopefully) Clearer wording,
> 7.= Nesting in traits, or nested traits, are future scope,
> 8= . Nested interfaces are future scope too.
>
> = Some benefits of using \ as a separator:
>
> -= a simple name can refer to nested classes:
>
>= ; Scope resolution was expanded to treat inner classes within the same c= lass as =E2=80=9Cin scope.=E2=80=9D This provides a more natural usage:<= /div>
>
> class Outer {
>   c= lass Inner {}
>   public function foo(Inner $inne= r) {}
> }
>
> - Standard =E2=80=9C= use=E2=80=9D statements can alias them:
>
> us= e Outer\Inner as Inner;
>
> But it also has so= me draw backs:
>
> - The engine doesn=E2=80=99= t know that Outer\Inner is a nested class and autoloaders will have to a= ccount for that. It will only ask for Outer\Inner.
>
<= div>> - You cannot simply refer to parent:>Inner, you have to expl= icitly ask for the parent by name: SomeParentClass\Inner.
>=
> A draft implementation (which is more of a proof-of-conc= ept) is available on GitHub.
>
>
>= ; Hello internals,
>
> As it seems that discus= sion has mostly died down, I'd like to put this towards a vote starting = on May 1, 2025.
>
> =E2=80=94 Rob
I intend to vote no. Fundamentally, this proposal adds a fo= rm of
"packaging" which only affects classes. There's no packa= ging for
constants or functions, unless you put them onto a cl= ass to make them
class constants and static methods. This is w= eird to me. I would
prefer that we work out something more gen= eral.

Thank you for your feedback!= It very much isn't packaging, this is closer to "friend" classes in C++= or nested classes in other languages (C#, Kotlin, Swift, Java, etc). I = do intend to focus on packaging (in-general) in the near future though.<= /div>

=
I am also worried that naming collisions are possible. So= mething like this:

```php
namespace A= {
     class B {}
}
<= br>
namespace {
    class A {
        class B {}
 = ;   }
}
```

Where= `A\B` refers to two possible things. I don't like this, and to
my knowledge, this type of confusion has not been possible in the
past. Of course, feel free to point it out if so. Note that method= s
and properties of the same name are disambiguated by syntax,= where
here the syntax is the same.


I should update the RFC to include this case,= thanks for pointing this out. This would cause the ole' "Cannot redecla= re class A\B" error. There is not any ambiguity here.

=E2=80=94 Rob
--28927a586adf4e2f8236aad3c8c4cafb--