Page 1 of 1

Class constant based on other class constants

Posted: Thu Mar 29, 2007 5:08 am
by anjanesh
Using PHP 5.2.1 :

Code: Select all

class cls
 {
        const a = 1;
        const b = 2;
        const c = 4;
        const x = self::a + self::b + self::c; // Error
 }
I get

Code: Select all

Parse error: syntax error, unexpected '+', expecting ',' or ';' in xxx.php on line [i]nn[/i]
Is a way to create a class-constant based on other class-constants ?

Thanks

Posted: Thu Mar 29, 2007 7:27 am
by stereofrog
No, you cannot use expressions in constants.
See viewtopic.php?t=65510