Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66321 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92979 invoked from network); 28 Feb 2013 11:40:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Feb 2013 11:40:33 -0000 Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.45 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 209.85.219.45 mail-oa0-f45.google.com Received: from [209.85.219.45] ([209.85.219.45:59208] helo=mail-oa0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 46/71-17375-F224F215 for ; Thu, 28 Feb 2013 06:40:32 -0500 Received: by mail-oa0-f45.google.com with SMTP id o6so3407907oag.32 for ; Thu, 28 Feb 2013 03:40:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=MozvnuFSsLzZVrcuJshs2qEp2A4SC3O0gaaqaKC8abg=; b=DQgwPH9ftXv3IaxxcXyB+x/+LVRAKeObiyFHgJFKPRrQQK99YsC6Rf/ZA4t0BsYBsB f9Ek8RX9xl+uIj51bSdZrIbRLuszZjqCSxtyuzRkPbWxBXocN46eX9FuHIeA1AXkaE4R 5ecs6jFeZr44OfLY4mbuh5Dz4TbIY3+4745kLJfshYmiO2DcDgRyNu5kT9j/nwXU/Ylv jW5eqKCynT9/pUDmk3Dm7j7vr9NVUag4bmLoRvcTZXh9vyyV11nFMxodC5NZvcuvZJ00 v3de/idD4v26KgrKyBaQrMbho8iF1Autc1hQHkNAZ3/juW+15+Zb/tnJ09O97pwXda8k KemQ== X-Received: by 10.182.113.40 with SMTP id iv8mr5285768obb.12.1362051629073; Thu, 28 Feb 2013 03:40:29 -0800 (PST) MIME-Version: 1.0 Received: by 10.76.113.178 with HTTP; Thu, 28 Feb 2013 03:40:08 -0800 (PST) In-Reply-To: References: <7E088EEC-ACB7-4977-BE00-CEA17ABD6EC3@me.com> Date: Thu, 28 Feb 2013 12:40:08 +0100 Message-ID: To: Sebastian Krebs Cc: Jens Riisom Schultz , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d04479f9585035304d6c75b97 Subject: Re: [PHP-DEV] I would like to write an RFC for the addition of an internal keyword From: linepogl@gmail.com (Lazare Inepologlou) --f46d04479f9585035304d6c75b97 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello, please read my comment inline... 2013/2/28 Sebastian Krebs > 2013/2/28 Jens Riisom Schultz > > > Hi everyone, > > > > (I got "hooked off" this discussion, so I have tried to keep up by > reading > > the digest... This makes it impossible for me to correctly interleave m= y > > comments, so I'll just "top post" or whatever the term is) (I'm sure th= is > > has been mentioned before but a forum would be so much more accesible > than > > this mailing list concept...) > > > > > > * In response to the argument that you want to be able to modify a > > framework or use it in an unintended manner: > > This would be possible by explicitly stating "namespace Framework;" in = a > > given php file. > > > > * In response to the argument that php has no assembly concept: > > I know this, but namespaces are as close as we get, and would effective= ly > > solve this. > > > > No. A namespace is in fact more or less just a prefix, that groups the > containing elements together. Beside the semantic meaning of grouping the= y > don't have any further abilities, or meaning. > Without knowing exact details I guess, that "internal" in C# is primary a > technical thing, that allows a compiler further optimizations, because he > definitely knows, that the function/method is only used within the assemb= ly > and is not required to do anything to expose it to the outside? > > Regardless of the technical details, it is still a fine way of applying encaptulation so you can't say that it is only a technical thing. > > > > > * In response to the argument that php already has accessibility > > restrictions with private and protected: > > This is true, but it does not solve all problems. Often you need classe= s > > to interoperate in a way that can only be facilitated by making > > functionality public. Also, there is no way to make a private or > protected > > class (since php has no assembly concept), though what I propose would > > likely birth the concept of private and protected classes as well. > > > > Maybe it's just me, but no: I've never had the need of what you describe > and where a public method wasn't apropriate anway... At least for a very > long time :D > > > > > > * In response to the argument that PHP does not restrict anyone from > > adding to a namespace: > > That is true, but say you were using Doctrine2. Would you ever make a p= hp > > file with "namespace Doctrine2;" in it, unless you wanted to modify > > Doctrine2, and hence you knew what you were doing, or accepted the risk= s? > > > > Well, yes. But extending/overriding a components method _always_ requires= , > that you know what you do, so why enforcing/encouraging hacks, instead of > the good old "protected"? > > "Protected" is used for extending classes. There is no mechanism to inherit and extend a namespace so "protected" is irrelevant here. > > > > > * In response to the concept of solving this through documentation: > > First off, this is not possible with the current phpdoc and phpdoc2 > > standards. Second off, problems like these should not be solved by > > documentation, imho, or of course I would not propose this. The C# > > designers seem to agree with me. And the Java designers, too (though th= ey > > have no internal keyword they do have a way of hiding framework specifi= c > > classes). > > > Actually Java has a concept that is identical to your proposal. The default access modifier (when no access modifier is written) is the "package" modifier (=3Daccessible from within the same package). > > Information hiding is one of the staples of good OOP, and the internal > > keyword would facilitate further information hiding in a way which is > > extremely hard to do as php is now. > > > > I would like to finish off with an example - I can tell there is a huge > > resistance to this but I do not agree with your arguments, so I'll give > it > > another shot. > > > > > > > namespace Framework; > > > > class PublicAPIClass { > > public function doStuff() { > > $instance =3D new InternalClass(); > > return $instance->doInternalStuff(); > > } > > > > internal public static function internalStuffHelper() {} > > } > > > > internal class InternalClass { > > public function doInternalStuff() { > > return PublicAPIClass::internalStuffHelper(); > > } > > } > > > > "internal public" is too much here, unless you want also to have "internal protected" like C#. I have extensivelly used "internal" and "package" in C# and Java, and I can tell you that "internal protected" is so rare that is not worh it. > > This doesn't explain, why the "InternalClass" should be hidden? Additiona= l > the "new" in "doStuff()" and the cyclic calls let me believe, that you'll > have a "tight coupling"-problem anyway. > > abstract class APIAbstract { > protected function doInternalStuff() { > return PublicAPIClass::internalStuffHelper(); > } > protected static function internalStuffHelper(); > } > > > > > > namespace NotTheFramework; > > > > $instance =3D new \Framework\PublicAPIClass(); > > $instance->doStuff(); > > > > // You would not be able to do the following things: > > use Framework\InternalClass; > > > > $instance =3D new \Framework\InternalClass(); > > > > \FrameWork\PublicAPIClass::internalStuffHelper(); > > > > And the question remains: Why _should_ I not be able to do this? If it is > that specific to the "PublicAPIClass" maybe it should be an abstract pare= nt > instead? Or a trait? > If it is _not_ that specific to "PublicAPIClass" ... well, ehm, this can'= t > be, because it calls "internalStuffHelper()", thus it is bound to the cla= ss > in any case. :) > > > > > > ?> > > > > Please read my example carefully, before simply writing it off. > > > > ...And a question: Am I wrong when I assume that this should be > > "relatively" easy to implement? > > > Relatively is the right word here. It might be easy for class members as the mechanism already exists. However, for direct namespace members there is no such concept. Can you make a proof-of-concept patch? > > -Jens Riisom Schultz > > > > > > On Feb 27, 2013, at 10:11 AM, Lazare Inepologlou > > wrote: > > > > > Hello, > > > > > > 2013/2/27 Jens Riisom Schultz > > > Hi, > > > > > > I just want to get a feel for whether the following idea would be > > instantly rejected (for example I get the feeling that adding keywords > is a > > big deal): > > > > > > Often, when writing frameworks, you need to make public or protected > > functionality or classes which should only be called from inside the > > framework. You CAN ensure this with a lot of ninja tricks and > > debug_backtrace, but it is very cumbersome and often hides your methods > and > > properties from class signatures. > > > > > > Therefore I would propose adding a C# style "internal" keyword. ( > > http://msdn.microsoft.com/en-us/library/7c5ka91b(v=3Dvs.80).aspx ) > > > > > > The idea is, simply, that functions, methods and classes marked as > > "internal" would only be accessible from within the namespace in which > they > > are defined. > > > > > > > > > The "internal" keyword in C# restricts access to the same *assembly*. > An > > assebly in .NET jargon is a .dll or a .exe, ie a package of code compil= ed > > by the same developper at once. As packages in PHP do not exist, or exi= st > > in some vague form (.phar, composer etc), I do not see how this keyword= , > > with its original meaning, could find a place here. > > > > > > Namespaces are not restricted to the same develloper and anyone can a= dd > > to them. Therefore, the meaning of the keyword would be totally differe= nt > > from that of C#. > > > > > > > > > > > > > > > For example the following class, "namespace Framework; internal class > > Something {}", would only be visible from within the "Framework" > namespace. > > > > > > I have a hunch that this would be relatively easy to implement. > > > > > > If noone objects I would attempt to create a patch and an RFC. > > > > > > What do you think? > > > > > > > > > -Jens Riisom Schultz > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > > > > > > -- > github.com/KingCrunch > Lazare Inepologlou Ing=C3=A9nieur Logiciel --f46d04479f9585035304d6c75b97--