PHP Constants Are Not Case Insensitive¶
PHP allowed the creation of case-insensitive constants with the function define. That was the third parameter to be passed, with a default, and often ignored value of false.
Since PHP 8.0, case-insensitive constants are not possible anymore. Creating a constant with both const and define only leads to case-sensitive global constant.
As a reminder, accessing a non-existing constant is a Fatal error, so an error on the case in a global constant leads to it.
PHP code¶
<?php
define('A', 1, true);
echo a;
echo A;
?>
Before¶
11
After¶
PHP Warning: define(): Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported
Warning: define(): Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported
PHP Fatal error: Uncaught Error: Undefined constant a
Fatal error: Uncaught Error: Undefined constant a
PHP version change¶
This behavior changed in 8.0