I know that you can create global constants in terms of each other using string concatenation:
define('FOO', 'foo'); define('BAR', FOO.'bar'); echo BAR;
will print "foobar".
However, I get an error message trying to do the same using class constants.
class foobar { const foo = 'foo'; const foo2 = self::foo; const bar = self::foo.'bar'; }
foo2 is detected without problems, but declaring a const bar will result in an error
Parse error: syntax error, unexpected '.', Pending ',' or ';'
I also tried using functions like sprintf (), but it doesnโt look like the left pair more than the string concatenator. '.
So, is there a way to create class constants in terms of each other in something more than a trivial set case, such as foo2?
php class const constants
selfsimilar May 7 '10 at 4:50 a.m. 2010-05-07 04:50
source share