A PHP internals mailing list discussion about a proposed RFC to add C++-style 'friend' class declarations to PHP. The RFC would allow a class to grant another class access to its non-public members. Key debate centers on Liskov Substitution Principle (LSP) violations: when a parent class grants friendship, subclasses can shadow private properties with incompatible visibility, causing runtime errors. Several solutions are discussed including requiring final classes, prohibiting property shadowing, upcasting syntax, and limiting friend access to protected (not private) members. The RFC author ultimately decides to restrict friendship to protected properties/methods/constants only to avoid LSP issues, triggering a 14-day cooldown period for the major change.

14m read timeFrom externals.io
Post cover image
143 Impressions