Re: Re: RFC: Nested Classes

From: Date: Wed, 07 May 2025 13:10:28 +0000
Subject: Re: Re: RFC: Nested 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 [email protected] to get a copy of this message
Hi

Am 2025-05-06 21:33, schrieb Rowan Tommins [IMSoP]:
The classes that you'll need to be aware of will exist whether this feature is added or not, and you'll already need to avoid conflicting with them - usually by simply avoiding the main namespace prefix of the library.
If this feature was designed like all the other implementations of private, I would not need to be aware of the other classes, since PHP would name-mangle the private symbol for me to ensure it doesn't conflict. In the simplest case it could compile
    class Foo {
        private class Bar { }
    }
As:
    class Foo {
    }
    class Foo$Bar {
    }
And rewrite all references inside of Foo to Foo$Bar (using Java's name mangling). This is effectively what Ilija's proposal for file-private classes did: https://externals.io/message/126331#126337. I think this would also be nicer on the autoloading impact. Since a private class is not usable outside of its container class, it doesn't make sense to attempt to autoload it individually, since to reference it, the container class must already be loaded (which means the private class is also already loaded). Best regards Tim Düsterhus

Thread (102 messages)

« previous php.internals (#127299) next »