1. const is used for defining class member variables. once defined, the value cannot be changed. Define defines global constants that can be accessed anywhere. 2. define cannot be defined in the class, but const can. 3. const cannot define the constant if (...) {constFOO & amp; #39;... SyntaxHigh in the condition statement.
1. const is used for defining class member variables. once defined, the value cannot be changed. Define defines global constants that can be accessed anywhere.
2. define cannot be defined in the class, but const can.
3. const cannot define constants in condition statements.
If (...){
Const FOO = 'bar'; // invalid
}
But
If (...){
Define ('foo', 'bar'); // valid
}
4. const uses a normal constant name, and define can use an expression as the name.
Const FOO = 'bar ';
For ($ I = 0; $ I <32; ++ $ I ){
Define ('bit _ '. $ I, 1 <$ I );
}
5. const can only accept static scalar, while define can use any expression.
Const BIT_5 = 1 <5; // invalid
But
Define ('bit _ 5', 1 <5); // valid
6. const is always case sensitive. however, define () can use the third parameter to define a case-insensitive constant.
Define ('foo', 'bar', true); www.2cto.com
Echo FOO; // BAR
Echo foo; // BAR
Summary:
Const is easy to read. it is a language structure, and define is a method. it is much faster to define const in compilation than define.
From the aa705123123 column