Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88092 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5194 invoked from network); 7 Sep 2015 12:24:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Sep 2015 12:24:28 -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.172 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 209.85.212.172 mail-wi0-f172.google.com Received: from [209.85.212.172] ([209.85.212.172:35649] helo=mail-wi0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B3/60-03021-BF18DE55 for ; Mon, 07 Sep 2015 08:24:27 -0400 Received: by wicge5 with SMTP id ge5so82212854wic.0 for ; Mon, 07 Sep 2015 05:24:24 -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=H4naWyP4uNnyt6ZrIMkun5xHO65wkCzVrp4ue7w+yEo=; b=AtGw44+H/9g7zzCLT2jyFF8fL4BNKm701+ajcc9FGLskkB6KZLoSyt9H7ZHQ1GLL73 hKqOe+OIz20VdRIkgNB05GvmJdAPEiBnNk7056bB53bsFasX2eCtfVsZGTug1d+t0CVE IFbvgB9uU2hmxBpW1sC6nunKJejpYdNNaYC6c7xnhpE9XntK7zEWNRN8mFDrrUQED1KR 9VSF4af8ULPWmnQvYe2PtR2Y+0mKRroBTp01fXUS1jNx6/Ar1lfZRRoHUKchI+vlMAoA pkms+0wbFs6EwMpOUGtXSV5W+fjOQyy0Lh8ulBAlf+PiC6DX1sXBNZDpYMhWzU61f+Ce jAKw== MIME-Version: 1.0 X-Received: by 10.180.88.195 with SMTP id bi3mr33852035wib.64.1441628664726; Mon, 07 Sep 2015 05:24:24 -0700 (PDT) Received: by 10.28.183.130 with HTTP; Mon, 7 Sep 2015 05:24:24 -0700 (PDT) In-Reply-To: <55ED368C.5010209@gmail.com> References: <20150827173432.GA71000@3006.local> <28.A5.59944.15C7CE55@pb1.pair.com> <55ED368C.5010209@gmail.com> Date: Mon, 7 Sep 2015 06:24:24 -0600 Message-ID: To: Stanislav Malyshev Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=bcaec550ac7e758908051f275462 Subject: Re: [PHP-DEV] Re: [RFC] [Concept] Class Constant visibility modifiers in PHP 7.1+ From: derokorian@gmail.com (Ryan Pallas) --bcaec550ac7e758908051f275462 Content-Type: text/plain; charset=UTF-8 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) 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) --bcaec550ac7e758908051f275462--