Re: Class constants

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2010-04-19 at 14:37 +0200, Peter Lind wrote:

> On 19 April 2010 14:24, Gary . <php-general@xxxxxxxxxxxxxxx> wrote:
> > On Mon, Apr 19, 2010 at 10:36 AM, Peter Lind wrote:
> >> On 19 April 2010 10:30, Gary wrote:
> >>> Should I be able to do this:
> >>>
> >>> class X
> >>> {
> >>>  const FOO = 'foo';
> >>>  const FOOBAR = X::FOO . 'bar';
> >>>
> >>> ...
> >>> }
> >
> >> So no, you shouldn't be able to do that.
> >
> > Okay. Why not?
> 
> Hate to ask, but did you at any point consider to read the PHP docs on
> this? The bit I sent or what you could gather from the link posted?
> 
> -- 
> <hype>
> WWW: http://plphp.dk / http://plind.dk
> LinkedIn: http://www.linkedin.com/in/plind
> Flickr: http://www.flickr.com/photos/fake51
> BeWelcome: Fake51
> Couchsurfing: Fake51
> </hype>
> 


Class constants must be defined with static values, not variables. They
are constants after all! If they relied on the value of a variable,
surely that would mean that their own value might change, so they would
just become regular variables not constants.

Is there a specific reason that you need to try and achieve this? Would
it not be better to have private or protected variables using getters
and setters if you need variable values?

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux