On Mon, May 4, 2026 at 12:50 PM Larry Garfield <[email protected]>
wrote:
> On Wed, Apr 29, 2026, at 12:30 PM, Daniel Scherzer wrote:
> > Hi internals,
> >
> > I'd like to add support for friendship in PHP.
> >
> > -Daniel
>
> There was a lot of related discussion around module/package/file
> visibility not too long ago that is also worth reviewing. Currently I am
> highly skeptical of friend classes, as I believe module-level visibility is
> more useful than class-level, in general.
>
I think that perfect should not be the enemy of good, and this also lays
the groundwork for namespace-level friends in the future. We shouldn't wait
for a potential future "module-level visibility" if we can have friends now.
>
> That said, were we to go this route, I agree that keywords would be the
> way to go for the reasons given in the blog post. Also, there's some
> plumbing already i place via aviz, at least for properties. In concept,
> the following should be possible:
>
> class User {
> friend UserFactory;
>
> public friend(set) string $name;
> }
>
I think having friends that can access everything is more helpful than a
new level of visibility - if you declare a class as a friend you already
know that the class exists and wants to access private implementation
details, so you can trust it to upload the class invariants.
-Daniel