Re: [RFC] [Discussion] Friends

From: Date: Sun, 10 May 2026 20:10:42 +0000
Subject: Re: [RFC] [Discussion] Friends
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-130817@lists.php.net to get a copy of this message
On Sun, May 10, 2026, at 18:28, Daniel Scherzer wrote: > Hi internals, > > I'd like to start the discussion for a new RFC about adding friendship in PHP. This is a > follow-up to a pre-RFC discussion thread > https://externals.io/message/130710. > > * RFC: https://wiki.php.net/rfc/friends > * Implementation: https://github.com/php/php-src/pull/21937 > > Thanks, > -Daniel Hi Daniel, I worked on the namespace visibility RFC before running out of time, and life isn't slowing down anytime soon; thus I wish you the best of luck with this one. First of all ... the RFC doesn't address several inheritance/override interactions worth working through. I'd invite you to read the thread here: https://externals.io/message/129147 -- you're going to run into a lot of the same issues in this RFC (and especially the follow-up namespace one), and you have some of the same problems. Take this example: class P { friend F; private int $x = 0; } class C extends P { protected int $x = 0; } class F { static function set(P $p, int $v) { $p->x = $v; } } F::set(new C, 5); // fatal The friend grant on P creates a non-local invariant that subclass authors of P can break without realizing. C's author, adding x for their own internal reasons, doesn't know they've broken some F that depends on the parent contract. C's tests pass. F's tests pass. Integration breaks at runtime in production. private(namespace) had the identical pathology. — Rob

« previous php.internals (#130817) next »