Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88093 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6963 invoked from network); 7 Sep 2015 12:27:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2015 12:27:25 -0000 Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.175 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 209.85.212.175 mail-wi0-f175.google.com Received: from [209.85.212.175] ([209.85.212.175:32840] helo=mail-wi0-f175.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5A/C0-03021-DA28DE55 for ; Mon, 07 Sep 2015 08:27:25 -0400 Received: by wiclk2 with SMTP id lk2so87135583wic.0 for ; Mon, 07 Sep 2015 05:27:22 -0700 (PDT) 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=gcDbdf1D9Ijzaz+JSIDFC/n1fO7FUlVt+BD7EiGrn3E=; b=QbWFik3KCBMpYOsyLCcXakGUrG0TXvGNxFSZQFIrGDM8vSNRe0ruuQ46E6vh5pr8lc Yk6Nr9Od1L+JkCyfvNZ7p9M6IbtEs/St+G/czYsYuBRbheaXet7SWiWv2HoS/AxeVr1q ZvWlE7+NBlWpaH0o4bzE8RF3IyhtfUxrp+4yT/8AiAIO7GI8TlmH7/pSsIREleED849c pljeL6Ym1m118H8BRpfhLXUfx/d7PCWPNRpSfpJcRVubeD89DDkik+Ws3dS2LalfjAic 85wYIhBkPGEfH+IVdMy1yQX+2RPZaPNru5VCteIsmMYCrT7pWZGD/4vyS7cdAOpnFwDY FAPg== MIME-Version: 1.0 X-Received: by 10.180.240.172 with SMTP id wb12mr34056954wic.64.1441628842596; Mon, 07 Sep 2015 05:27:22 -0700 (PDT) Received: by 10.28.183.130 with HTTP; Mon, 7 Sep 2015 05:27:22 -0700 (PDT) In-Reply-To: References: <20150827173432.GA71000@3006.local> <28.A5.59944.15C7CE55@pb1.pair.com> <55ED368C.5010209@gmail.com> Date: Mon, 7 Sep 2015 06:27:22 -0600 Message-ID: To: Stanislav Malyshev Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c2775c0fa042051f275fd0 Subject: Re: [PHP-DEV] Re: [RFC] [Concept] Class Constant visibility modifiers in PHP 7.1+ From: derokorian@gmail.com (Ryan Pallas) --001a11c2775c0fa042051f275fd0 Content-Type: text/plain; charset=UTF-8 On Mon, Sep 7, 2015 at 6:24 AM, Ryan Pallas wrote: > > > On Mon, Sep 7, 2015 at 1:02 AM, Stanislav Malyshev > wrote: > >> Hi! >> >> > Funny you should propose this now, I was wanting this feature just the >> > other day. This would be a useful addition, and clean up a strange >> > inconsistency: why can methods and properties have visibility modifiers, >> > but not constants? >> >> Private and protected methods and properties are private for a reason - >> they may be radically changed or gone when the code is changing, and >> thus external code should not rely on them, and the way to ensure it is >> to deny that code access to them. However, I have hard time seeing how >> that would apply to constants - they shouldn't really change, and if >> they do, they either shouldn't be constant, or something in your world >> changed fundamentally (i.e. scientists discovered that PI actually >> equals to 4). I wonder if you find in your code constant that you need >> to hide because you foresee it changing - should it really be a constant >> at all? >> > > > For me a common use case is DB abstraction. I have an abstract base class > that implements a bunch of functionality based on protected static members, > which are to be set in the implementing class. Now these properties are > constant for the implementing class (table name, column definition, etc) > but I have to put them in a static member to prevent outside access. So > now I have the problem, where if someone else maintains my code they see a > static member in the class they may think its acceptable to change it in > some function at run time, meanwhile if they were constants it would be > very obvious that they should not be changed. The reason they are in static > members is A) to provide visibility modifiers and B) to share a single > value across all instances, however given that C) they are constant through > meaning and usage, the should instead be protected consts. For an example > of a base class of this type, you can look at my framework's version (NOTE: > I'm not advocating my framework, its kinda crap but it works well for my > purposes) http://bit.ly/1EN59Ty (class) http://bit.ly/1NdkGgL (docs) > Looks like I changed to constants because someone did write a function that modified the value of TABLE_NAME in a project I was working on. So now the internals of the models are available everywhere (sad). > I fully support this idea, and would be glad to provide any help I can > (though that probably just means writing tests since I don't know C) > --001a11c2775c0fa042051f275fd0--