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
Quoted text · 6 lines
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
Quoted text · 23 lines
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,
-DanielHi 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); // fatalThe 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
Ah, okay, I think I understand what the issue is. Using an example of User and UserFactory, the issue is that
- When
UsermarksUserFactoryas a friend - and
Useris not marked as final - and
Userhas private non-static properties or methods[1] - and
UserFactoryhas some expression that accesses a private property or method
then
- subclasses of
Usercould have properties/methods of the same name that shadow the property/method inUser - if the subclass property/method is not public, and does not list
UserFactoryas a friend, then theUserFactoryaccess would trigger visibility errors
That... is an interesting scenario - and I'm not quite sure that friendship is to blame. If this is replacing code that used ReflectionObject to change the property, or ReflectionMethod built from the object, then it was already targeting the shadowing version from the child class.
Basically, with friends, the developer is making a logic error and assuming that $p instanceof P means that get_class($p) === P::class rather than a subclass.
Somehow, existing code within the User class doesn't have this problem
class User {
private $id;
public static function setId(User $u, $value) {
var_dump($u);
$u->id = $value;
var_dump($u);
}
}
class Child extends User { protected $id; }
$c = new Child();
User::setId($c, 123);
I guess there are a few options to address this
- require classes with friends to be final (but then PHPUnit can't mock them)
- prohibit shadowing of private properties/methods if a class has friends (exposes some implementation details to subclasses, but hopefully not too many)
- make
$u->idalways refer to the base property in a friend the same way that it does within the user class itself (but that means that properties/methods that intentionally shadow and are public or protected and visible to the friend that previously referred to the subclass shadow now refer to the parent class) - add some kind of upcasting to make it clear which property is being referenced,
<$u as User>->id = ...
I actually think that upcasting might be the simplest and cleanest, especially if we restrict it to only places where it is required for friendship - it can only be used as a temporary way to access properties or methods, i.e. no $u2 = $u as User;, and can only be used to cast subclasses into their parent class, when the calling code is a friend of that parent class.
Surprisingly I think adding an entirely new syntax would actually result in the fewest breaking changes when userland classes add friends, because there is no ambiguity. $u->id always refers to the id on whatever class $u happens to be, including applying any shadowing; if you want to be sure to access the base User::$id, use <$u as User>->id.
Before I dive in and actually add that, what do people think?
-Daniel
[1] I'm excluding static properties and methods since those are normally accessed as User::$prop and User::$staticMethod(), same with constants
Quoted text · 33 lines
__
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,
-DanielHi 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); // fatalThe friend grant on P creates a non-local invariant that subclass authors of P can break without realizing. C's author, adding
xfor 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
Ah, okay, I think I understand what the issue is. Using an example of User and UserFactory, the issue is that
- When
UsermarksUserFactoryas a friend- and
Useris not marked as final- and
Userhas private non-static properties or methods[1]- and
UserFactoryhas some expression that accesses a private property or methodthen
- subclasses of
Usercould have properties/methods of the same name that shadow the property/method inUser- if the subclass property/method is not public, and does not list
UserFactoryas a friend, then theUserFactoryaccess would trigger visibility errorsThat... is an interesting scenario - and I'm not quite sure that friendship is to blame. If this is replacing code that used ReflectionObject to change the property, or ReflectionMethod built from the object, then it was already targeting the shadowing version from the child class.
It's basically a violation of LSP since LSP guarantees we can use a subclass in place of the parent class. A friendship is basically a visibility modifier on the entire class, making the entire class "public" to the friend. Your RFC says it isn't visibility, but it is.
Basically, with friends, the developer is making a logic error and assuming that
$p instanceof Pmeans thatget_class($p) === P::classrather than a subclass.
I don't think that is a valid argument in OOP. Framing the friend's call as a developer logic error rejects LSP itself: the whole point of polymorphism is that callers programmed against the parent's contract can be handed subclass instances. If those instances are allowed to silently violate the contract, the bug isn't in the calling code; it's in the language.
Quoted text · 10 lines
Somehow, existing code within the
Userclass doesn't have this problemclass User { private $id; public static function setId(User $u, $value) { var_dump($u); $u->id = $value; var_dump($u); } } class Child extends User { protected $id; } $c = new Child(); User::setId($c, 123);I guess there are a few options to address this
- require classes with friends to be final (but then PHPUnit can't mock them)
- prohibit shadowing of private properties/methods if a class has friends (exposes some implementation details to subclasses, but hopefully not too many)
- make
$u->idalways refer to the base property in a friend the same way that it does within the user class itself (but that means that properties/methods that intentionally shadow and are public or protected and visible to the friend that previously referred to the subclass shadow now refer to the parent class)- add some kind of upcasting to make it clear which property is being referenced,
<$u as User>->id = ...I actually think that upcasting might be the simplest and cleanest, especially if we restrict it to only places where it is required for friendship - it can only be used as a temporary way to access properties or methods, i.e. no
$u2 = $u as User;, and can only be used to cast subclasses into their parent class, when the calling code is a friend of that parent class.Surprisingly I think adding an entirely new syntax would actually result in the fewest breaking changes when userland classes add friends, because there is no ambiguity.
$u->idalways refers to theidon whatever class$uhappens to be, including applying any shadowing; if you want to be sure to access the baseUser::$id, use<$u as User>->id.Before I dive in and actually add that, what do people think?
By the end of it, I basically arrived at a calculus that makes a sorta sense. Visibility levels are sets of callers, partial-ordered by inclusion. An override is admissible iff the child's caller set is a superset of the parent's at the call site. P's caller set for $x with friend F is {P, F}; C's shadowing with protected $x gives {C ∪ descendants(C)}; incomparable, so the override violates LSP.
Through that lens, we can look at your options you identified.
Option 1 basically kills the entire feature.
Option 3 breaks polymorphism. It throws away legitimate overrides.
Option 4 is an escape hatch, not a solution. There's already RFCs for "as" in-progress, so you'd step on some toes there. Heh, I think I have even proposed "as" before and ... from experience, competing with someone's in-progress RFC without discussion with them beforehand is a great way to have people get mad at you on this list.
Option 2 is probably the closest "right" answer. It prevents there from being invalid caller sets and can provide meaningful error messages at compile time: "name collides with friended private variable; must friend with class F or change the name x".
Another option to consider is not allowing private variables/methods to be accessed by friends. Only protected variables/methods. This allows inheritance to work as normal and guarantees overrides are compatible.
— Rob
Quoted text · 10 lines
Surprisingly I think adding an entirely new syntax would actually result in the fewest breaking changes when userland classes add friends, because there is no ambiguity.
$u->idalways refers to theidon whatever class$uhappens to be, including applying any shadowing; if you want to be sure to access the baseUser::$id, use<$u as User>->id.Before I dive in and actually add that, what do people think?
By the end of it, I basically arrived at a calculus that makes a sorta sense. Visibility levels are sets of callers, partial-ordered by inclusion. An override is admissible iff the child's caller set is a superset of the parent's at the call site. P's caller set for
$xwithfriend Fis {P, F}; C's shadowing withprotected $xgives {C ∪ descendants(C)}; incomparable, so the override violates LSP.Through that lens, we can look at your options you identified.
Option 1 basically kills the entire feature.
Option 3 breaks polymorphism. It throws away legitimate overrides.
Option 4 is an escape hatch, not a solution. There's already RFCs for "as" in-progress, so you'd step on some toes there. Heh, I think I have even proposed "as" before and ... from experience, competing with someone's in-progress RFC without discussion with them beforehand is a great way to have people get mad at you on this list.
Option 2 is probably the closest "right" answer. It prevents there from being invalid caller sets and can provide meaningful error messages at compile time: "name collides with friended private variable; must friend with class F or change the name x".
Another option to consider is not allowing private variables/methods to be accessed by friends. Only protected variables/methods. This allows inheritance to work as normal and guarantees overrides are compatible.
— Rob
Honestly, this seems like the easiest model to explain to people. A friend class has the same access as a child class, ie, it gets protected but not private access. That's a very simple rule to document and explain, and seems like it would side-step a number of issues. (We had a similar conversation for aviz, IIRC, which is how we ended up on private => final and readonly => protected(set) simplifying a lot of issues.)
That said, I am still skeptical. This seems simple enough, but I worry that it's still attacking the general problem in too specific a way (compared to modules or similar).
--Larry Garfield
On Sun, May 10, 2026 at 9:28 AM Daniel Scherzer daniel.e.scherzer@gmail.com wrote:
Quoted text · 6 lines
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
After feedback from Rob and Larry, I'm planning to switch friendship to just allow access to protected properties/methods/constants, unless anyone has any other suggestions for avoiding the LSP issues.
-Daniel
On Thu, May 14, 2026 at 12:29 PM Daniel Scherzer < daniel.e.scherzer@gmail.com> wrote:
Quoted text · 8 lines
On Sun, May 10, 2026 at 9:28 AM Daniel Scherzer < daniel.e.scherzer@gmail.com> 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,
-DanielAfter feedback from Rob and Larry, I'm planning to switch friendship to just allow access to protected properties/methods/constants, unless anyone has any other suggestions for avoiding the LSP issues.
Seeing no further feedback, I have adjusted the RFC and the implementation to only allow access to protected properties/methods/constants. This qualifies as a "major change" and triggers a 14 day cooldown period.
-Daniel
Hi
Am 2026-06-04 01:13, schrieb Daniel Scherzer:
Seeing no further feedback, I have adjusted the RFC and the implementation
to only allow access to protected properties/methods/constants. This qualifies as a "major change" and triggers a 14 day cooldown period.
I've given the RFC another read and stumbled over:
Friendship is not inherited. If UserFactory has a subclass NamedUserFactory, that subclass cannot access the protected details of User
From what I see this would also be in violation of the LSP, because subclasses are not fully interchangeable with the top-level class. It would also need clarification what the relevant “authority” for accessibility is: Is it the class name of the actual class or is it the defining class of the method in question?
i.e.
class User { friend UserFactory; protected function __construct() {
} }
class UserFactory {
public function foo() { new User(); }
}
class ChildUserFactory extends UserFactory { }
$f = new ChildUserFactory();
$f->foo(); // Is this legal? ChildUserFactory is not a friend, but
foo() is defined in UserFactory.
Best regards
Tim Düsterhus
Quoted text · 14 lines
Hi
Am 2026-06-04 01:13, schrieb Daniel Scherzer:
Seeing no further feedback, I have adjusted the RFC and the implementation
to only allow access to protected properties/methods/constants. This qualifies as a "major change" and triggers a 14 day cooldown period.I've given the RFC another read and stumbled over:
Friendship is not inherited. If UserFactory has a subclass NamedUserFactory, that subclass cannot access the protected details of User
From what I see this would also be in violation of the LSP, because subclasses are not fully interchangeable with the top-level class. It would also need clarification what the relevant “authority” for accessibility is: Is it the class name of the actual class or is it the defining class of the method in question?
i.e.
class User { friend UserFactory; protected function __construct() {} }
class UserFactory { public function foo() { new User(); } } class ChildUserFactory extends UserFactory { } $f = new ChildUserFactory(); $f->foo(); // Is this legal? ChildUserFactory is not a friend, butfoo() is defined in UserFactory.
Best regards
Tim Düsterhus
Since foo() is defined in UserFactory rather than ChildUserFactory, the method call still works - I was going to go add a test for this, but I already have one, see
https://github.com/DanielEScherzer/php-src/blob/9f3c8dcac5032f11cf8b8c0ee6a4a2611a2a3933/Zend/tests/friends/not_inherited.phpt
Specifically, friendship is checked based on where the caller is defined, i.e. for inherited methods (here ChildUserFactory::foo(), in my test Baz::testFooAccess()) the parent class which defines the function is what needs to be a friend.
I've added this clarification to the RFC text with a clearer example (and updated the implementation with the new example test) - even when foo() is overridden, using parent::foo() would work. As long as the actual access is done from code defined in a friend, things work.
Let me know if the updated RFC text is still unclear.
-Daniel
Hi!
On Thu, Jun 4, 2026 at 2:15 AM Daniel Scherzer daniel.e.scherzer@gmail.com wrote:
Seeing no further feedback, I have adjusted the RFC and the implementation to only allow access to protected properties/methods/constants. This qualifies as a "major change" and triggers a 14 day cooldown period.
Thanks for RFC, gave it a look and want to add to other's concerns. Even though the goal of this RFC sounds useful, I strongly believe it should be fully inverted: not User declares its friends, but all the clients get access to the internals if they need. Many have pointed out the violation of LSP, but I would add that the current variant actually violates most of SOLID principles. It has been implicitly stated already by other commenters in this or previous thread, but I'd like to elaborate on this.
SRP: if User declares UserFactory as a friend, it means that for some reason it already knows why the factory needs it. In other words, it goes beyond its responsibility.
OCP: the list of friends will be hardcoded inside the User class with no possibility to change/extend that.
LSP: already covered.
DIP: the fact that User defines its friends is already a soft cyclic dependency.
If we look from another angle, a User declaring its friends is semantically the same as if it described some of its inheritors, which would also vialote many concerns: a class must know neither its clients nor possible inheritors. The only thing it could do is declare such things abstractly.
So, instead, as I've said, I would go for a fully inverted solution: the clients themselves declare that they are accessing some other class' internals, and it would be purely the client's responsibility if that solution is OK architecturally.
It could look similar to using the traits, for example:
class UserFactory
{
accesses User; // or it could be specific methods inside { ... }
}
Or maybe even:
class UserFactory internal to User, SomeOtherClass // exact word is TBD, and correspond to current PHP reserved words/lexer.
In this case this "friendship" would just become a sugar for how we do these things currently anyway using reflection and/or bound closures. But honestly, I would avoid using the word "friendship" for this mechanic, because it is too vague or probably even "vulgar".
Regards,
Alexandr Egorov.
Hi Alexandr,
On Sun, Nov 15, 2026 at 4:26 PM Alexander Egorov amego2006@gmail.com wrote:
Quoted text · 5 lines
Hi!
On Thu, Jun 4, 2026 at 2:15 AM Daniel Scherzer daniel.e.scherzer@gmail.com wrote:
Seeing no further feedback, I have adjusted the RFC and the implementation to only allow access to protected properties/methods/constants.
This qualifies as a "major change" and triggers a 14 day cooldown period.Thanks for RFC, gave it a look and want to add to other's concerns. Even though the goal of this RFC sounds useful, I strongly believe it should be fully inverted: not User declares its friends, but all the clients get access to the internals if they need. Many have pointed out the violation of LSP,
The violation of LSP was about access to private properties, which has been removed in the latest version of the RFC.
but I would add that the current variant actually violates most of SOLID principles. It has been implicitly stated already by other commenters in this or previous thread, but I'd like to elaborate on this.
SRP: if User declares UserFactory as a friend, it means that for some reason it already knows why the factory needs it. In other words, it goes beyond its responsibility.
The "S" in SOLID is for the single responsibility principle - when the User class changes other things shouldn't need to change too. But, the use case for friends is for when this is already being violated by using reflection, or (ab)using the public API by having internal methods be public. This is just making things clearer.
OCP: the list of friends will be hardcoded inside the User class with no possibility to change/extend that.
That is because this is an internal detail of the User class! OCP is that classes should be "open to extension, but closed for modification" - friendship falls under modification, not extension, because friends are not in the same type hierarchy. Thus, OCP suggests that the list of friends should be hardcoded without a way to change it at runtime.
LSP: already covered.
DIP: the fact that User defines its friends is already a soft cyclic dependency.
There is future scope for supporting abstractions as friends, per the RFC future scope includes
Adding support for inherited friendship (“UserFactory and all of its subclasses are all friends of User”)
Adding support for namespaces as friends (“Any class in \My\Library\Namespace is a friend of User”)
but, I'll note that switching to friends should not introduce new dependencies - if the existing code was making things public, it was going against other principles, and if it was using reflection, the class was implicitly supporting manipulation that went through reflection rather than the stable public interface. This just switches that implicit support to something explicit.
Quoted text · 9 lines
If we look from another angle, a User declaring its friends is semantically the same as if it described some of its inheritors, which would also vialote many concerns: a class must know neither its clients nor possible inheritors. The only thing it could do is declare such things abstractly.
So, instead, as I've said, I would go for a fully inverted solution: the clients themselves declare that they are accessing some other class' internals, and it would be purely the client's responsibility if that solution is OK architecturally.
It could look similar to using the traits, for example:
class UserFactory
{
accesses User; // or it could be specific methods inside { ... }
}Or maybe even:
class UserFactory internal to User, SomeOtherClass // exact word is TBD, and correspond to current PHP reserved words/lexer.
While this could be done, there is a benefit to the friendship being declared on the User class - it tells developers when changing the User class that there is another class (here the UserFactory) that is coupled with the internal details of the User class. If friendship was declared on UserFactory instead, then developers changing the "internal" details of the User class are less likely to see that UserFactory also needs to be updated and just hope that tests catch the mistake.
In this case this "friendship" would just become a sugar for how we do these things currently anyway using reflection and/or bound closures. But honestly, I would avoid using the word "friendship" for this mechanic, because it is too vague or probably even "vulgar".
I'm unclear why you consider friendship too vague, since it is the term used in other languages (c.f. https://en.wikipedia.org/wiki/Friend_class) or why it would be considered vulgar.
Regards,
Alexandr Egorov.
-Daniel
Hi! Thanks for the reply!
On Sat, Nov 21, 2026 at 2:26 AM Daniel Scherzer daniel.e.scherzer@gmail.com wrote:
The "S" in SOLID is for the single responsibility principle - when the User class changes other things shouldn't need to change too. But, the use case for friends is for when this is already being violated by using reflection, or (ab)using the public API by having internal methods be public. This is just making things clearer.
Not really. Single responsibility is about the zone (scope) of responsibility of the class (what problem it solves), not about changing or not the contract. The User's responsibility is to model the user in some way - that is its single responsibility. Gating access to any of its methods, if needed, either public or not, is a separate scope, and architecturally must be external to the User according to SRP.
We first had a User class, which is already self-sufficient for the goal of modelling a User, then we decided we need a factory for instantiating a User - a separate scope of responsibility. And according to SRP, we would only need to create the Factory class. In your solution, we would also need to modify the User class, despite that nothing about modelling the User itself changed. That's what breaks the SRP principle already. But let's assume for the moment we're OK with that. It leads to another problem. If we then decide to add a UserRepository class, which would also require access to some internals of User, we would again need to modify the User class. So, here comes the violation of OCP.
That is because this is an internal detail of the User class! OCP is that classes should be "open to extension, but closed for modification" - friendship falls under modification, not extension, because friends are not in the same type hierarchy. Thus, OCP suggests that the list of friends should be hardcoded without a way to change it at runtime.
Like, literally, instead of extending the list of possible "intruders", we're always modifying the User class.
There is future scope for supporting abstractions as friends, per the RFC future scope includes
And that's exactly the problem which an abstract solution could solve as one of possible solutions. Instead of always modifying the User for each new "intruder", it could just define such access as an abstraction, and any other future client would not need to be hardcoded inside the User, but instead only implement the abstraction in any way. Like, in C#, for example, it is the "internal" thing, which is an abstract declaration of who can access protected methods. Technically speaking, "public/private/protected" is already a similar abstraction: it defines access levels on the abstract level without knowing anything about the exact consumers of the class.
... and if it was using reflection, the class was implicitly supporting manipulation that went through reflection rather than the stable public interface. This just switches that implicit support to something explicit.
Not really. If any other class uses reflection or bound closures to access the internals of User and rely on them, it is completely beyond the scope of User's responsibility (otherwise SRP is already broken). As I've mentioned in my previous message, it is the sole responsibility of the consumer if it decides to use such an approach, taking all the risks. Meanwhile, even though intruding into class's internals is not a good thing, doing it from external is a cleaner solution according to considerations above, than going to User itself and modifying it. In the end, if it all happens inside the same project/package, it already means something has to be refactored instead of kludging.
Quoted text · 8 lines
It could look similar to using the traits, for example:
class UserFactory
{
accesses User; // or it could be specific methods inside { ... }
}Or maybe even:
class UserFactory internal to User, SomeOtherClass // exact word is TBD, and correspond to current PHP reserved words/lexer.
While this could be done, there is a benefit to the friendship being declared on the User class - it tells developers when changing the User class that there is another class (here the UserFactory) that is coupled with the internal details of the User class. If friendship was declared on UserFactory instead, then developers changing the "internal" details of the User class are less likely to see that UserFactory also needs to be updated and just hope that tests catch the mistake.
Well, changing the contracts of classes happen now and then internally to the project, and it always entails discovering the consumers. But it is never a responsibility of the class itself to know about all of its consumers. Such linkage from the class to consumers is exactly what breaks the architecture, no matter if those links are hard or soft, like comments or some meta-information, like attributes. If such consumers can't be easily discovered, that is a problem of another kind, not related to the "friendship" mechanic.
I'm unclear why you consider friendship too vague, since it is the term used in other languages (c.f. https://en.wikipedia.org/wiki/Friend_class) or why it would be considered vulgar.
By that I meant that since we're talking about a formal programming language, the term should be more technical from my pov. Specifically the "Friend" term is used only inside C++. Any other languages which give similar mechanics don't use it: "internal" in C#, "fileprivate" in Swift, etc.
-Daniel
Regards,
Alexandr Egorov.
Hi internals,
On Sun, May 10, 2026 at 9:28 AM Daniel Scherzer daniel.e.scherzer@gmail.com wrote:
Quoted text · 6 lines
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
I'd like to resume discussion of this RFC since I was reminded of it at MergePHP yesterday.
As far as I can recall and find, there was no remaining feedback that I needed to address. The current proposal is that friendship allows access to protected but not private parts of a class.
Since it's been a few months, this RFC discussion is considered inactive, and per our policy a new cooldown period is required. This will not go to vote before November 27.
Please let me know if you have any feedback, -Daniel
Quoted text · 11 lines
Hi internals,
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,
-DanielI'd like to resume discussion of this RFC since I was reminded of it at MergePHP yesterday.
As far as I can recall and find, there was no remaining feedback that I needed to address. The current proposal is that friendship allows access to protected but not private parts of a class.
Since it's been a few months, this RFC discussion is considered inactive, and per our policy a new cooldown period is required. This will not go to vote before November 27.
Please let me know if you have any feedback, -Daniel
I had a quick glance at the implementation and can't see any issues. However, I'm not convinced by the feature and will be voting against it.
Moreover, I'm not sure I agree with the following premise in the RFC:
The use of reflection for bypassing visibility restrictions in non-test code is generally frowned upon, and should not be recommended.
While most usages of the reflection API are indeed in test code I don't understand why production code should allegedly not use it. Especially as in this case it seems to me that making the properties private and using reflection to by-pass the visibility by related components is very much a valid use case.
Best regards,
Gina P. Banyard