> However, I have hard time seeing how that would apply to constants

I don't see what their not changing has to do with their visibility.

It's not hard to see a legitimate use case for private constants, a case
that springs to mind is where you use a public bitmask for some
configuration option but want to keep the shift or mask constants private,
because they might change, and you don't want to leak that implementation
detail. They are still constant at runtime, but over the course of the life
of the codebase they can definitely change, and, they shouldn't be a static
member or normal variable.



On Mon, Sep 7, 2015 at 8:02 AM, Stanislav Malyshev <smalys...@gmail.com>
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?
> --
> Stas Malyshev
> smalys...@gmail.com
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to