I'm overriding a constant with case in-sensitive parameter. But php doesn't give me "constant already defined" error. I've enabled E_ALL,E_STRICT errors. Example:1
define('ONE',1000);
define('one',2000,true);
echo ONE; // prints 1000
echo one; // prints 2000
In the second line, i'm making 'one' as another constant with case in-sensitive, which means redefining 'ONE'. But PHP gives no error/warning.
Example:2
define('ONE',1000,true);
define('one',2000);
echo ONE; // prints 1000 with constant already defined notice
echo one; // prints 1000
Here i can get error notice.
What's the difference between these two code blocks.?
From the documentation:
Note: Case-insensitive constants are stored as lower-case.
Thus, when trying to define the lower-cased version of the constant in your second example, the constant is already defined due to the prior case-insensensitive definition of a constant with the same name.
define('ONE', 1000, true); // defines strtolower("ONE") = "one"
define('one', 2000); // error redefining "one"
In the first scenario, there is no such collision:
define('ONE', 1000); // defines "ONE"
define('one', 2000, true); // defines strtolower("one") = "one"
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