Re: Class constants

From: Date: Mon, 19 Apr 2010 08:36:02 +0000
Subject: Re: Class constants
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-304196@lists.php.net to get a copy of this message
On 19 April 2010 10:30, Gary . <php-general@garydjones.name> wrote: > Should I be able to do this: > > class X > { >  const FOO = 'foo'; >  const FOOBAR = X::FOO . 'bar'; > > ... > } > > ? > > Because I can't. I get "syntax error, unexpected '.', expecting > ',' or > ';'". I assume this is because the constants are like statics which > can't be initialised by functions etc. but is there really any logic > behind this? > It very often pays to read the PHP docs. From http://pl.php.net/manual/en/language.oop5.constants.php : "The value must be a constant expression, not (for example) a variable, a property, a result of a mathematical operation, or a function call. " So no, you shouldn't be able to do that. -- <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>

« previous php.general (#304196) next »