Is it possible to redefine class constants (in PHP)?
e.g.
class B {
const C_ThisIsAConstant = 1;
}
class A extends B {
self::C_ThisIsAConstant = 2;
}
No, you cannot redefine a constant (except with runkit_constant_redefine), that's why is called CONSTANT. Short answer: No.
A constant value cannot change during the execution of the script. By default, a constant is case-sensitive. By convention, constant identifiers are always uppercase.
The constant variable values cannot be changed after its initialization. In this section we will see how to change the value of some constant variables. If we want to change the value of constant variable, it will generate compile time error.
A PHP constant once defined cannot be redefined. A PHP variable can be undefined as well as can be redefined. rather it can only be defined using define(). We can define a variable using a simple assignment operation(=).
No, of course not. Then they wouldn't be "constants."
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