Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:51652 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72274 invoked from network); 9 Mar 2011 19:43:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2011 19:43:04 -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.220.170 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.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:50128] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/A0-03777-748D77D4 for ; Wed, 09 Mar 2011 14:43:04 -0500 Received: by vxb39 with SMTP id 39so814436vxb.29 for ; Wed, 09 Mar 2011 11:43:01 -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=GDBp0to5mS/FOtmgnpqlJUXzMTbDHt4ZNog0BsLfUOs=; b=DfL1Li3+WRS4ptIcEtgC6QxqsQSK6KZ752/25oe9SOilkH30XUpB1147MzZyrQQgW6 kdYcJdxDpwaVwQ8uQtZV3BJGy6JKf2IEnjfmWCbGj9Zb4atxZ5kHXrtkZP33eO6A+gGx THSJUYEXF08BsqCEw0dOO7R4CwtUtZfOpfnUM= 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=BiVNy8qD1SW7Q0MiU1rfRZ5YhLFBCKWQK18VR2+UA063JRnR66KUQrWhifUkiPiCkw 0VQYGLJD8ksJffZUi3Sey4C7Z9VwF8nhc1WOrsD1uLLFHXi+AlDbijWjiLYKPMXvGOk+ kPbDP8nyCI6SQOKbPmsIlKUY0ubKPFdGiUtKc= MIME-Version: 1.0 Received: by 10.52.91.231 with SMTP id ch7mr6453039vdb.14.1299699781195; Wed, 09 Mar 2011 11:43:01 -0800 (PST) Received: by 10.220.125.67 with HTTP; Wed, 9 Mar 2011 11:43:01 -0800 (PST) In-Reply-To: References: <8423995CEEEA844CB2F964B14BCA94CD043ABC80@PRODEXCHANGE02.ilchildcare.org> <8423995CEEEA844CB2F964B14BCA94CD043AC586@PRODEXCHANGE02.ilchildcare.org> Date: Wed, 9 Mar 2011 16:43:01 -0300 Message-ID: To: Chad Fulton Cc: Jarrod Nettles , Hannes Landeholm , "internals@lists.php.net" , "james.butler@edigitalresearch.com" Content-Type: multipart/alternative; boundary=20cf307c9e14c5d6f6049e11efb9 Subject: Re: [PHP-DEV] Class Access Modifiers From: martinscotta@gmail.com (Martin Scotta) --20cf307c9e14c5d6f6049e11efb9 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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. > yes, every class should specify its own visibility. Inheritance here does not make any sense, you only will be able to use private classes at the cost of your entire class hierarchy being private to= o . > > 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? > Well, that depends on who is your end-user? Current object model works well for small-to-mid size application, but it does not allows to write *safe* libraries safe: to don't break client code, because of wrong client code. > 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 > > --20cf307c9e14c5d6f6049e11efb9--