In PHP when you define a class level constant as in:
const MY_CONSTANT = 'hello constant';
Why can't you initialize this value with a function such as
const MY_FILEPATH = dirname(dirname(__FILE__)) . '/heres-my-file.php';
In short: The constants are replaced while parsing, but functions are executed while interpreting. The parser simply cannot know to what it should set the value of the content.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With