Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:79879 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 13954 invoked from network); 23 Dec 2014 03:34:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Dec 2014 03:34:16 -0000 Authentication-Results: pb1.pair.com smtp.mail=leight@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=leight@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.53 as permitted sender) X-PHP-List-Original-Sender: leight@gmail.com X-Host-Fingerprint: 74.125.82.53 mail-wg0-f53.google.com Received: from [74.125.82.53] ([74.125.82.53:37031] helo=mail-wg0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 98/20-11368-7B2E8945 for ; Mon, 22 Dec 2014 22:34:16 -0500 Received: by mail-wg0-f53.google.com with SMTP id l18so8032511wgh.40 for ; Mon, 22 Dec 2014 19:34:11 -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=ThcEbu3/rqeMkHDKBnlslD+HrZfx6aGgqiSBFA2xvKU=; b=hAnhbcwviJzpF0VdRf8zYxj5K9YCQFllQAwUw4a9CPp5pySnIFK2dUtglYqEda2+Ef L8Fyg5XZqOGc6jvkyOiPPvIk5/4MathRCAu7yv/BirTiut/DJ0FqQP3rkjo+kEjFZSME YPnR0hPOhRHjKWq2kFiXmuIMgQ6RR0uFtz2SYojuFvscwV1rnU22Tv3N8ghEpJJd976R iqRbjBA99Bpvmg+7HRxLomZHfFTnK5E0VNFStdyeQF7kk+d40Kn46vXJRfqk2FG2GkhH KGH8lRIx1g+P6zg0bmICSeR51uAN7Q8QbDQP6guE7X0qq1cKXKGp0YgCfCfapg1n9375 xzSg== MIME-Version: 1.0 X-Received: by 10.180.72.199 with SMTP id f7mr37304232wiv.58.1419305651528; Mon, 22 Dec 2014 19:34:11 -0800 (PST) Received: by 10.216.50.139 with HTTP; Mon, 22 Dec 2014 19:34:11 -0800 (PST) In-Reply-To: References: Date: Tue, 23 Dec 2014 03:34:11 +0000 Message-ID: To: "guilhermeblanco@gmail.com" Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Package private class From: leight@gmail.com (Leigh) On 23 December 2014 at 00:32, guilhermeblanco@gmail.com wrote: > Hi internals, > > I finalized a new proposal for PHP. It consists into adding support for > package-private classes in the language. > > A package private class is basically a class that can only be instantiated > in its declared namespace. This means that you cannot extend, implement or > use a class, interface or trait outside of declared namespace. It can be > referenced outside of the package, but instantiation can only be done there. > > Other languages such as Java and C# consider package-private class as a > top-level class without any declared visibility. PHP cannot enforce this as > it would be an incredible BC break, but we can reuse an already declared > keyword "private" to fit this purpose. A class declared without any > visibility modifier is considered "public" and works exactly as it > currently does. The same applies to a class written with "public" keyword > (ie. public class Foo {}). > > Most of checks are done at compile time and only instantiation is done at > runtime (the only place I found out it could be done). Performance impact > seems negligible as only one top condition is added during instantiation > bytecode executor. > > > At this stage I want to collect implementation feedback. Explanation is > done above and the extensive amount of tests self explains what the entire > purpose of this feature is. RFC will be created together with voting once > I'm able to gather some considerations. > > Link to PR: https://github.com/php/php-src/pull/947 > > > Cheers, > > -- > Guilherme Blanco > MSN: guilhermeblanco@hotmail.com > GTalk: guilhermeblanco > Toronto - ON/Canada Hey Guilherme, Good work, namespace visibility on classes and functions is something I have been working on over the past few months. The reason I haven't created an RFC is because I couldn't decide on what "private" and "protected" should mean for a class or function within a namespace. To me, a private class can only be instantiated within it's own namespace (this seems the same as you have defined), but can be typehinted and used anywhere else. Maybe I was wrong to try and include "protected" in my own work, as it caused me the most problems when trying to define what it should mean. My original feeling was that it should mean it can only be instantiated in it's own namespace or sub-namespaces. I also considered a strict "visibility" view, private classes would not be "visible" outside of their own namespace, and protected would not be "visible" outside of their own or child namespaces ("visible" meaning no type hints or usage too). It is reassuring to see that your approach is the same as my initial feelings, the accessibility keywords define instantiation usage, rather than a strict visibility. I haven't looked at your patch in detail. My PoC code revolved around comparing the start of class names with the current namespace. Is yours the same? How do you feel about extending this to functions? Thank's for the work on this. I wasn't sure I had the willpower to finish my patch for PHP7, it's nice to see you have the same idea. Cheers, Leigh.