Re: Class constants

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

 



On 19 April 2010 10:30, Gary . <php-general@xxxxxxxxxxxxxxx> 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>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[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