Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66313 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 68357 invoked from network); 28 Feb 2013 06:57:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Feb 2013 06:57:03 -0000 Authentication-Results: pb1.pair.com smtp.mail=ibmurai@me.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ibmurai@me.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain me.com designates 17.158.232.237 as permitted sender) X-PHP-List-Original-Sender: ibmurai@me.com X-Host-Fingerprint: 17.158.232.237 nk11p03mm-asmtpout002.mac.com Solaris 10 1203 Received: from [17.158.232.237] ([17.158.232.237:32808] helo=nk11p03mm-asmtp002.mac.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1F/80-63468-BBFFE215 for ; Thu, 28 Feb 2013 01:57:01 -0500 Received: from [192.168.1.64] (188-182-36-146-static.dk.customer.tdc.net [188.182.36.146]) by nk11p03mm-asmtp002.mac.com (Oracle Communications Messaging Server 7u4-26.01(7.0.4.26.0) 64bit (built Jul 13 2012)) with ESMTPSA id <0MIX00DWB4MS7O90@nk11p03mm-asmtp002.mac.com> for internals@lists.php.net; Thu, 28 Feb 2013 06:56:55 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.9.8327,1.0.431,0.0.0000 definitions=2013-02-28_01:2013-02-28,2013-02-28,1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=2 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1203120001 definitions=main-1302270356 Content-type: multipart/alternative; boundary="Apple-Mail=_F20FF313-3A62-41A5-B4AE-48FCF60BC4D9" Message-ID: <7E088EEC-ACB7-4977-BE00-CEA17ABD6EC3@me.com> MIME-version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Date: Thu, 28 Feb 2013 07:56:54 +0100 References: To: "internals@lists.php.net" In-reply-to: X-Mailer: Apple Mail (2.1499) Subject: Re: [PHP-DEV] I would like to write an RFC for the addition of an internal keyword From: ibmurai@me.com (Jens Riisom Schultz) --Apple-Mail=_F20FF313-3A62-41A5-B4AE-48FCF60BC4D9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii 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 my comments, so I'll just "top post" or whatever the term is) = (I'm sure this 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 = effectively solve this. * 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 classes = 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. * 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 = php file with "namespace Doctrine2;" in it, unless you wanted to modify = Doctrine2, and hence you knew what you were doing, or accepted the = risks? * 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 = they have no internal keyword they do have a way of hiding framework = specific classes). 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. doInternalStuff(); } internal public static function internalStuffHelper() {} }=20 internal class InternalClass { public function doInternalStuff() { return PublicAPIClass::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(); ?> 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? -Jens Riisom Schultz On Feb 27, 2013, at 10:11 AM, Lazare Inepologlou = wrote: > Hello, >=20 > 2013/2/27 Jens Riisom Schultz > Hi, >=20 > 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): >=20 > 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. >=20 > Therefore I would propose adding a C# style "internal" keyword. ( = http://msdn.microsoft.com/en-us/library/7c5ka91b(v=3Dvs.80).aspx ) >=20 > 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. >=20 >=20 > 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 = compiled by the same developper at once. As packages in PHP do not = exist, or exist in some vague form (.phar, composer etc), I do not see = how this keyword, with its original meaning, could find a place here. >=20 > Namespaces are not restricted to the same develloper and anyone can = add to them. Therefore, the meaning of the keyword would be totally = different from that of C#. >=20 >=20 >=20 > =20 > For example the following class, "namespace Framework; internal class = Something {}", would only be visible from within the "Framework" = namespace. >=20 > I have a hunch that this would be relatively easy to implement. >=20 > If noone objects I would attempt to create a patch and an RFC. >=20 > What do you think? >=20 >=20 > -Jens Riisom Schultz > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >=20 >=20 --Apple-Mail=_F20FF313-3A62-41A5-B4AE-48FCF60BC4D9--