Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89040 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91477 invoked from network); 2 Nov 2015 14:42:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Nov 2015 14:42:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=guilhermeblanco@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=guilhermeblanco@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.178 as permitted sender) X-PHP-List-Original-Sender: guilhermeblanco@gmail.com X-Host-Fingerprint: 209.85.214.178 mail-ob0-f178.google.com Received: from [209.85.214.178] ([209.85.214.178:32996] helo=mail-ob0-f178.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/D5-42726-56677365 for ; Mon, 02 Nov 2015 09:42:45 -0500 Received: by obbwb3 with SMTP id wb3so96336721obb.0 for ; Mon, 02 Nov 2015 06:42:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=D4zbRwAOQ8GLLyZbQvrG4tRTKHpOdFKAGxHC/NVq7yI=; b=hjKQhLFNBUhOpPUpkZ2JGQjTc7Kb4o02g5XXgwvnXJRcUHnsmMI9+pgrwUA8Jqm5Bm 9apTy6NV2yH0z7T/5YF1M8vaHQuvtzs5yZliCGfPSbrbbK+zS2QlOgd1HnloBx6Rbm4l YyyR5NOvmeDr/ygp9719iHp9lN0J5HloaSDe+UOLRXVQgeVHX5rLNdFfGs+LgBRlUYD4 8cXeOej5wfEitg8TdEEVLGe764xyOFK7apSbAx/Ekx50NSVzGWfIixwiwf061tyb1S2O efihFWC8xkMKqlvIU+x+kRLmckm1F4UWTA9fWUKITc4B2CUbPCnp9Ee+3ILV1RohB/rr 50LA== MIME-Version: 1.0 X-Received: by 10.60.69.65 with SMTP id c1mr14112138oeu.38.1446475362179; Mon, 02 Nov 2015 06:42:42 -0800 (PST) Received: by 10.202.206.3 with HTTP; Mon, 2 Nov 2015 06:42:41 -0800 (PST) Received: by 10.202.206.3 with HTTP; Mon, 2 Nov 2015 06:42:41 -0800 (PST) In-Reply-To: <5637540E.3070005@php.net> References: <5637540E.3070005@php.net> Date: Mon, 2 Nov 2015 09:42:41 -0500 Message-ID: To: francois Cc: georges , PHP internals Content-Type: multipart/alternative; boundary=001a1133151e23a67a05238fca16 Subject: Re: [PHP-DEV] Friend class/function From: guilhermeblanco@gmail.com ("guilhermeblanco@gmail.com") --001a1133151e23a67a05238fca16 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, One thing that should be worth mentioning is that my approach of private classes is decoupled in 2 parts. The first one as the ability to prevent instantiation outside of namespace and sub-namespaces. The second is the ability to access protected members, which matches your wish of friend classes nicely. However, I could not even tackle the second part without discussing and agreeing on the first one, so I limited the scope of my wish in order to simplify overall RFC phase. Regards, On Nov 2, 2015 7:17 AM, "Fran=C3=A7ois Laupretre" wrote: > Hi Georges, > > Le 01/11/2015 17:04, georges a =C3=A9crit : > >> =E2=80=8BHi php internals, >> >> I recently discovered =E2=80=8Bthe "friendship concept" in c++ and i rea= lly love >> the concept. >> And i wonder if the php internals would be interested to implements it i= n >> the next 7.x major version. >> >> > You may be interested by an article I wrote some weeks ago about adapting > the 'friendship' concept to PHP ( > http://tekwire.net/joomla/projects/ideas/php-friend). IMO, we should > enable friendship from classes and/or namespaces, with and without > inheritance, giving four cases : class, class and descendants, namespace, > namespace and sub-namespaces. > > One more detail : I wouldn't set the 'friend' information on the same lin= e > as the class declaration. First reason is that it already contains > 'extends' and 'implements' stances. 2nd reason is that the information is > not required by the compiler to start compiling the class body. So, > 'friend' lines can be part of the class body. > > Use cases go well beyond test classes. There are many cases where you nee= d > to access methods and/or even whole classes from a set of known locations= , > but don't want to make them public. Today, the only way is to use protect= ed > access but it implies class inheritance which, often, is not an option. A= n > example is symfony using the '@internal' tag to mark > class/properties/methods which mustn't be accessed from the outside of > symfony (see > http://symfony.com/doc/current/contributing/code/bc.html#using-our-classe= s). > Information is better than nothing but a way to enforce access restrictio= ns > would be welcome. > > About Guilherme's proposal : it seems fine but, IMHO, the 'friend' concep= t > includes it, is easier to implement, and goes much further. > > Regards > > Fran=C3=A7ois > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a1133151e23a67a05238fca16--