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;
}
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, of course not. Then they wouldn't be "constants."
First: No, it is not possible to redefine class constants. Its impossible in every language, because otherwise a constant wouldnt be constant.
But what you are doing is possible, because you dont redefine a class constant, instead you define a one unique constant for every class.
I have published my framework YAPAF on github.com. Let's call it alpha-state. Anyhow, YAPAF is able to change the value of a class constant (see https://github.com/SchulteMarkus/YAPAF/blob/master/tests/ManipulateConstantTest.php).
You can't redefine "constants" because they are contant.
If you're trying to change a constant defined in an included file, then you can defining the constant before the include:
PROCESS_NAME will be "MIKE".
It outputs
int(2)
.http://codepad.org/GQR9HI5M