Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51650 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 69499 invoked from network); 9 Mar 2011 19:34:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2011 19:34:52 -0000 Authentication-Results: pb1.pair.com smtp.mail=martinscotta@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=martinscotta@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: martinscotta@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:39597] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 56/00-03777-B56D77D4 for ; Wed, 09 Mar 2011 14:34:52 -0500 Received: by vws10 with SMTP id 10so803179vws.29 for ; Wed, 09 Mar 2011 11:34:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=LI5SkLekZdH4vWTXXVyGDb3SbgNnUwmQYBg+SckoR4I=; b=cxNgxBzl+jsoGm4JjvGW64aulM23DBjQvp+hBdsVANttBtfScA0MZZWl0efstSM6oc 2pXiwhopF4eGVGGtlap754JzJgiwLU5hyOW9AF6PKxrOgiRGEhNoOiu3GOCp8b0RfwwV kOQBidipxAiWB5wqPwm1ZaRSRqW2iVetkDxEE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=tQKlWOvySNGNJXv4UyKhaPAGUsEW583L2lNU3xuieSiL7qgiF4pdPeLysJFYcOViLC p5AMSZagrYPxu6B5PPkLG9V276KbME2nIYFp2jxU1aSOTyyUHpn2hbeG1W22mnkY/7pW jiUGBBd0k9lpxRpe9RZt6x38wnllQMa9p6Q2w= MIME-Version: 1.0 Received: by 10.52.18.101 with SMTP id v5mr3759965vdd.134.1299699234902; Wed, 09 Mar 2011 11:33:54 -0800 (PST) Received: by 10.220.125.67 with HTTP; Wed, 9 Mar 2011 11:33:54 -0800 (PST) In-Reply-To: References: <8423995CEEEA844CB2F964B14BCA94CD043ABC80@PRODEXCHANGE02.ilchildcare.org> <8423995CEEEA844CB2F964B14BCA94CD043AC586@PRODEXCHANGE02.ilchildcare.org> Date: Wed, 9 Mar 2011 16:33:54 -0300 Message-ID: To: Chad Fulton Cc: Jarrod Nettles , Hannes Landeholm , "internals@lists.php.net" , "james.butler@edigitalresearch.com" Content-Type: multipart/alternative; boundary=20cf3054aa6b361577049e11cf2b Subject: Re: [PHP-DEV] Class Access Modifiers From: martinscotta@gmail.com (Martin Scotta) --20cf3054aa6b361577049e11cf2b Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable class modifiers should follow the same modifiers and semantic that methods: T_PUBLIC, T_PROTECTED and T_PRIVATE should be used. nowadays all classes are public... T_PUBLIC: everybody can see it, everybody can subclass it T_PROTECTED: visible only within its ns, but everybody can subclass it T_PRIVATE: visible only within the same ns, subclass allowed only within it= s ns namespace A { class Pub { } protected class Prot { } private class Priv { } } namespace B { class Foo extends \A\Prot { } // legal, no matter Foo visibility class Baz extends \A\Priv { } // error, no matter Baz visibility new Foo(); // ok new Baz(); // ok new \A\Pub(); // ok new \A\Prot(); // error, class is protected new \A\Priv(); // error, class is private } in the example "A" exposes classes "Pub" and "Prot", but you cannot instantiate class "Prot" So... does it mean that class "Priv" cannot be used outside "A"? no, you ca= n always return a reference. namespace A { class F { static function getE() { return new E; } } private class E { } } var_dump( \A\F::getE() ); // object \A\E Martin Scotta On Wed, Mar 9, 2011 at 3:23 PM, Chad Fulton wrote: > Hello, > > On Wed, Mar 9, 2011 at 10:02 AM, Jarrod Nettles > wrote: > > Interesting question. My gut tells me not (as does three years of C# > experience). I=92m sure that everyone will have a different opinion on th= is > but to me it seems taboo that a child class override the visibility of th= e > parent class. For example, PHP currently does not allow you to override a > method with a lower or higher visibility than the parent =96 I can=92t go= from > protected to public or vice versa. Visibility must be maintained througho= ut > the class hierarchy. > > > > Actually, class properties and methods can have a higher visibility > than their parents, just not a lower one. > > E.g.: > > > error_reporting(E_ALL | E_STRICT); > > class foo { > protected function bar() { > > } > } > > class baz extends foo { > public function bar() { > > } > } > > class foobar extends baz { > protected function bar () { > > } > } > > ?> > > You get the following error: > > Fatal error: Access level to foobar::bar() must be public (as in class > baz) in ... > > ------- > > That said, I wouldn't think that visibility modifiers on classes need > to follow the same pattern. In the case of properties and methods, I > think the rationale is that child classes should be compatible from an > interface standpoint with their parents. That same logic may not > transfer to class visibility modifiers. > > I am certainly no expert, but I'm curious what the use case is for > class visibility modifiers? > > On Wed, Mar 9, 2011 at 7:11 AM, Hannes Landeholm > wrote: > > Currently I'm forced to use huge internal classes for my framework > because > dividing them into smaller classes would expose internal behavior to the > "outside"... the application layer. > > > > This doesn't necessarily make sense to me. Isn't it the > end-developer's problem if they start instantiating classes in weird > ways? > > It doesn't seem the same as having a private method, since in that > case the end-developer presumably already has an object instance, and > you want to guide them to the correct interface for interacting with > it, whereas in an application, one would think that the end-developer > wouldn't simply be instantiating classes by themselves all over the > place. > > Chad > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --20cf3054aa6b361577049e11cf2b--