Re: RFC: Nested Classes (was: short and inner classes)

From: Date: Mon, 31 Mar 2025 20:35:04 +0000
Subject: Re: RFC: Nested Classes (was: short and inner classes)
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  Groups: php.internals 
Request: Send a blank email to internals+get-126983@lists.php.net to get a copy of this message
On Mon, Mar 31, 2025, at 21:45, Rob Landers wrote: > Hello internals, > > I have significantly revamped the RFC (again). Key changes to the RFC: > > 1. More (realistic) examples, > 2. Since enums are basically specialized classes, they are allowed to 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; 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 class as “in scope.” > This provides a more natural usage: > > class Outer { > class Inner {} > public function foo(Inner $inner) {} > } > > - Standard “use” statements can alias them: > > use Outer\Inner as Inner; > > But it also has some draw backs: > > - The engine doesn’t know that Outer\Inner is a nested class and autoloaders will have to > account for that. It will only ask for Outer\Inner. > > - You cannot simply refer to parent:>Inner, you have to explicitly ask for the parent by > name: SomeParentClass\Inner. > > A draft implementation (which is more of a proof-of-concept) is available on GitHub. I accidentally forgot to include the link to the RFC: https://wiki.php.net/rfc/short-and-inner-classes — Rob

« previous php.internals (#126983) next »