Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to redefine PHP constants?

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;
}
like image 322
JCm Avatar asked Mar 25 '11 01:03

JCm


People also ask

Can you redefine a constant in PHP?

No, you cannot redefine a constant (except with runkit_constant_redefine), that's why is called CONSTANT. Short answer: No.

Can we change the value of constant during the execution of the script?

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.

Can you redefine a constant in C?

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.

What are the differences between PHP constants and variables?

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(=).


1 Answers

No, of course not. Then they wouldn't be "constants."

like image 133
Explosion Pills Avatar answered Sep 23 '22 19:09

Explosion Pills