I have a constant called PREFIX defined in constants.php. In class Foo, I would like to create a static class constant with PREFIX as the prefix. But I get a syntax error on that const definition line.
require_once 'constants.php';
class Foo {
const FOO_CONST = PREFIX . 'bar';
public function __construct() {
}
}
In PHP a
constmust be a value, not an expression.So
const FOO_CONST = 'foo' . 'bar';won’t work either.You have to use
defineor a class member that gets initialized in the constructor instead of aconst. Initializing a class member outside a class method with an expression does not work either.