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.

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

Reply via email to