"const is defined at compile time" may not be true, depending on what you call "defining".
Although you can't define a const inside an if, like
if ($c === 'a') {
const c = a;
}
else {
const c = b;
}
# Results in a parse error
you can assign it a value depending on a conditionnal 'define' constant
$a = 1;
if ($a === 1) {
define('a', 'one');
}
else {
define('a', 'two');
}
const c = a;
# Valid, c equals "one"
https://onlinephp.io/c/b8227