Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80162 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59742 invoked from network); 4 Jan 2015 23:49:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Jan 2015 23:49:40 -0000 Authentication-Results: pb1.pair.com header.from=francois@tekwire.net; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=francois@tekwire.net; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain tekwire.net does not designate 212.27.42.2 as permitted sender) X-PHP-List-Original-Sender: francois@tekwire.net X-Host-Fingerprint: 212.27.42.2 smtp2-g21.free.fr Received: from [212.27.42.2] ([212.27.42.2:59506] helo=smtp2-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/20-57266-291D9A45 for ; Sun, 04 Jan 2015 18:49:39 -0500 Received: from moorea (unknown [82.240.16.115]) by smtp2-g21.free.fr (Postfix) with ESMTP id 1717E4B0143 for ; Mon, 5 Jan 2015 00:47:47 +0100 (CET) Reply-To: To: Date: Mon, 5 Jan 2015 00:49:34 +0100 Message-ID: <002b01d02879$17ce3c10$476ab430$@tekwire.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AdAoeRd4uB/HgSApRZq7KNoH2L5Nbw== Content-Language: fr X-Antivirus: avast! (VPS 150104-1, 04/01/2015), Outbound message X-Antivirus-Status: Clean Subject: Friend classes revived From: francois@tekwire.net (=?iso-8859-1?Q?Fran=E7ois_Laupretre?=) Hi, I know the subject was discussed years ago, and it was decided not to implement 'friend class' declarations (see https://bugs.php.net/bug.php?id=3D34044). But the discussions occurred ten years ago, and things (and people) may = be different now.=20 Unfortunately, there is no easy-to-use and fast solution for this yet. = Most projects have asked for such a feature for years but, till now, they = still have to rely on a big warning in the documentation. Some, like symfony, = also add an '@internal' tag in their phpdoc block. This can be checked in an = IDE but that's information, not access restriction. IMHO, such a feature would be a valuable addition for PHP 7. If you = agree, I will write an RFC. The feature I was thinking about would be globally similar to C++ friend classes, except that a PHP friend class would have access to protected resources, but not private ones (private would remain private). The inheritance rules would be similar to C++ rules (adapted from = Wikipedia as it originally includes access to private resources) : * Friendships are not symmetric =96 If class A is a friend of class B, = class B is not automatically a friend of class A. * Friendships are not transitive =96 If class A is a friend of class B, = and class B is a friend of class C, class A is not automatically a friend of class C. * Friendships are not inherited =96 A friend of class Base is not automatically a friend of class Derived and vice versa; equally if Base = is a friend of another class, Derived is not automatically a friend and vice versa. * Access due to friendship is inherited =96 A friend of Derived can = access the protected members of Derived that were inherited from Base (simpler than = the C++ rule as friend classes and derived classes have the same access = rights). Another idea would be to base access restriction on namespaces, but, = IMO, namespaces would not bring the precision we need : each class needs to define which classes are accepted as 'friends'. Please comment. Regards, Fran=E7ois