What are the limitations of defining constants in PHP classes, particularly in terms of initialization methods?

When defining constants in PHP classes, you cannot use initialization methods or perform any logic to set the value of the constant dynamically. Constants must have a fixed value that is known at compile time. To work around this limitation, you can use class constants for static values that do not require dynamic initialization, and use static properties with a static method for values that need to be calculated or set dynamically.

class MyClass {
    const MY_CONSTANT = 'fixed value';

    public static function getDynamicValue() {
        return 'dynamic value';
    }
}

echo MyClass::MY_CONSTANT; // Output: fixed value
echo MyClass::getDynamicValue(); // Output: dynamic value