On Thu, Apr 24, 2025, at 17:20, Tim Düsterhus wrote: > Hi > > On 4/24/25 17:09, Rob Landers wrote: > > Thank you for your feedback! I think you would then have the problem that > > was pointed out by Levi the other day; where you would then have ambiguity. > > If you could have both private and public names in the same namespace, then > > you would end up not knowing which one was being referred to. > > That is a design error in the RFC then.
This was very deliberate after much feedback and careful design. People were quite clear (including yourself, if I recall) that they didn't want a new syntax. Since there is no new syntax, there is no way to tell (from the outside) whether A\B\C refers to a nested class or an outer class. That's by design and mirrors other languages and how they handle nested classes. > > > Also, it is worth pointing out that private symbols are *not* "invisible" > > or "non-existent" from outside classes. They emit their own errors: > > https://3v4l.org/PEGeA that indicate you tried to access something you > > shouldn't be able to. This is different than when you try to access > > something that actually doesn't exist: https://3v4l.org/nWVPV > > Fair enough about the error message. You can also access them with > Reflection or the Closure hack. They are nevertheless ”non-existent” > from the public API PoV: https://3v4l.org/Us6VV > > <?php > > class Foo { > private string $bar = "foo"; > private function foo(): array {} > } > > class Bar extends Foo { > private array $bar = []; > > private function foo($foo): int {} > } > > class Baz extends Bar { > public self $bar; > } > > $baz = new Baz(); > $baz->bar = $baz; > > var_dump($baz); > > In subclasses I can “redefine” private properties or methods and they do > not interact at all. Properties have separate storage locations and can > have differing types. Methods do not need to have compatible signatures > either. > > Best regards > Tim Düsterhus > I'm not sure what you are saying here. I mean, what you are saying is self-evident but I don't understand how it applies to nested classes. You can write the following without any issues: class Foo { private class Bar {} } class Bar extends Foo { private class Bar extends Foo {} } And it will work just fine. You could even make the nested classes public if you want to, or one of them private and one of them public. As mentioned in the RFC, the nested class is bound to the lexical scope of the class it is written in. So Foo\Bar and Bar\Bar are different classes altogether in the example above. — Rob