On Wed, Apr 2, 2025, at 07:54, Viktor Khramov wrote:
> Hi Rob.
> The examples in this RFC only describe usage within classes as far as I can see.
> Does this finally solve the factory methods issue? https://externals.io/message/126452
>
> пн, 31 мар. 2025 г. в 23:38, Rob Landers <[email protected]>:
>> __
>> 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
Ah, good catch Viktor,
I added a factory pattern as an example.
— Rob